Python in Unreal Engine — The undocumented parts

Some python features are not documented at all. Such as declaring struct or enum.
  • how to get a subsystem in python
  • how to return struct or array from a python function
  • how to pip install package into Unreal Engine

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)
  • When declaring ENUM, you should use values of numbers from 0 to N. You can skip numbers but Unreal expects that there is always an enum value of 0.
  • Struct must inherit from unreal.StructBase or its subtype. It didn't work from me if I inherited from the unreal.Struct. Fields in a struct are defined by unreal.uproperty
  • Don’t forget to mark your blueprint library functions as static

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

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Salary Trends for DevOps and Cloud Native Professionals

A PROGRAMMER……Mystrey !

Building Git in Elixir — Part 4 (Store Nested Trees as Merkle Tree)

Community Mojo

Actual Power of Open Source

Securely Send Attachments via Python

PART -2 Migration of AWS DocumentDB to Atlas MongoDB with rollback strategy(Failover)

Hosting Django Chat App on Heroku with Redis & Daphne.

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
Filip Sivák

Filip Sivák

More from Medium

Using the U.S. Census Bureau API with Python

Learning Phyton-Assignment

Visualization in Python — Creating Word Cloud

How to get around of the “UnicodeEncodeError: ‘utf-8’ codec can’t encode character …: surrogates…