Python Scripting
Call the Scooter Utilities runtime library from Unreal Editor Python scripts.
Every Scooter Utilities Blueprint node is also available in the editor's Python environment through the unreal module. You don't need to set anything up beyond enabling Python.
Enabling Python
In the Main Menu, go to Edit > Plugins.
Enable Python Editor Script Plugin, then restart the editor.
Open the Python console: in the Output Log, switch the command box from Cmd to Python.
NOTE
Editor Python runs only in the editor, not in packaged games.
Name Mapping
Unreal converts the C++ names automatically:
- Classes drop their
Uprefix:UJSONBlueprintLibrarybecomesunreal.JSONBlueprintLibrary. - Enums drop their
Eprefix, and their values become upper snake case:EFileLocation::ProjectSavedbecomesunreal.FileLocation.PROJECT_SAVED. - Functions and parameters become snake case:
GetCallingBlueprintNamebecomesget_calling_blueprint_name. - Output pins come back as a tuple, after the return value if there is one.
| Blueprint category | Python class |
|---|---|
| JSON | unreal.JSONBlueprintLibrary |
| File IO | unreal.FileIO |
| Global Config | unreal.ScooterUtilsBPLibrary |
| Debug Print | unreal.SUDebugPrint |
| Blueprint Reflection | unreal.BPReflection |
| Lorem Ipsum | unreal.LoremIpsumGenerator |
For what each function does, see the matching Blueprint node page.
TIP
Run help(unreal.JSONBlueprintLibrary) in the Python console to list every function and its exact signature.
Examples
Build some JSON and save it to the project's Saved folder:
import unreal
json = unreal.JSONBlueprintLibrary.add_field(unreal.JSONFieldType.STRING, "", "name", "Bob")
json = unreal.JSONBlueprintLibrary.add_field(unreal.JSONFieldType.NUMBER, json, "health", "100")
ok, path = unreal.FileIO.save_text_to_file(unreal.FileLocation.PROJECT_SAVED, "Scripts/player.json", json)
unreal.log(f"Saved: {ok} -> {path}")Read it back and pull out a value:
ok, text, path = unreal.FileIO.load_file_to_string(unreal.FileLocation.PROJECT_SAVED, "Scripts/player.json")
found, name = unreal.JSONBlueprintLibrary.get_string_field(text, "name")Write to a log file from a script:
unreal.SUDebugPrint.log_message("Scripts.log", unreal.DebugLevel.WARNING, "Batch import finished", "ImportScript")