Python in Unreal Engine — The undocumented parts

Some python features are not documented at all. Such as declaring struct or enum.

Single-purpose script — How to automatically import a whole folder of assets

import unreal
from pathlib import Path
IMPORT_DIR = Path(r"G:\path\to\fbx_folder")
assert IMPORT_DIR.exists()
tasks = []
for fbx in IMPORT_DIR.glob("*.fbx"):
asset_import_task = unreal.AssetImportTask()
asset_import_task.filename = str(fbx)
asset_import_task.destination_path = '/Game/Geometry'
asset_import_task.automated = True
tasks.append(asset_import_task)

asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
asset_tools.import_asset_tasks(tasks)
You can run a python script using the command “py”. This means you can also run python script in Movie Render Pipeline before or after render using Start/End commands

How to run python automatically on engine startup

How to get a reference to a subsystem in Python

Subsystems are accessed via special nodes in blueprints
aes = unreal.get_editor_subsystem(unreal.AssetEditorSubsystem)

Defining struct, enum and class in python and use it in a blueprint

MyPythonFunction declared lower, returning custom struct PythonUnrealStruct (output pin splitted)

Using C++ types in python

How to use pip install with Unreal Engine

Installing directly in Unreal Engine

How to call python function through REST API

import unreal@unreal.uclass()
class RemoteClass(unreal.BlueprintFunctionLibrary):

@unreal.ufunction(static=True)
def remote():
print("Hello from remote!")
{
"objectPath": "/Engine/PythonTypes.Default__RemoteClass",
"functionName": "remote"
}

How to call python asynchronously from C++

FString PythonCommand(TEXT("SomePythonFunction()"));Future = FFunctionGraphTask::CreateAndDispatchWhenReady([=]
{
IPythonScriptPlugin::Get()->ExecPythonCommand(*PythonCommand);
});

Debugging python running in Unreal Engine

Python internals

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store