Skip to content

The unreal_engine API

Starcel runs Python inside Unreal with UnrealEnginePython. Everything the plugin exposes is in the unreal_engine module, which only exists inside the game. For autocomplete, Content/Scripts/unreal_engine holds generated stubs.

import unreal_engine as ue
from unreal_engine import FVector, FRotator, FTransform, FLinearColor
from unreal_engine.classes import Actor, StaticMeshActor, KismetSystemLibrary
from unreal_engine.enums import EComponentMobility

uobjects

Every Unreal object you get in Python is a uobject. It has fast native methods in snake_case:

loc = actor.get_actor_location()
actor.set_actor_location(FVector(0, 0, 100))
actor.get_name()
actor.actor_destroy()

and reaches every Unreal property and function by its CamelCase name, through reflection:

actor.bCanBeDamaged = True                  # same as set_property('bCanBeDamaged', True)
vec = actor.GetActorLocation()              # K2_ functions work without the prefix
actor.CharacterMovement.MaxWalkSpeed = 600.0

Native methods are faster; use them when there is one.

Classes, structs and enums

from unreal_engine.classes import KismetSystemLibrary, WidgetBlueprintLibrary
from unreal_engine.structs import SomeStruct
from unreal_engine.enums import EDrawDebugTrace

name = KismetSystemLibrary.GetObjectName(actor)     # static functions
s = SomeStruct(Foo='Bar', Test=17.22)

Functions with output parameters return them after the return value:

hit, hit_result = KismetSystemLibrary.LineTraceSingle(...)

Finding and loading

cls = ue.find_class('StaticMeshComponent')
obj = ue.find_object('...')
tex = ue.load_object(ue.find_class('Texture2D'), '/Game/Textures/logo')

Spawning

Only actors can be spawned, into a world:

from unreal_engine_tools import get_world
from unreal_engine.classes import Actor

world = get_world()
a = world.actor_spawn(Actor, FVector(0, 0, 0), FRotator(0, 0, 0))

A Blueprint asset isn't an actor class; spawn its generated class ('/Game/X.X_C'). Starcel's load_blueprint_class() and spawn() do this for you.

Blueprints

bp_actor.call('MyCustomEvent with_an_arg')
result = bp_actor.call_function('GetFloatValue', 1.5)
other = self.uobject.get_property('target')

Logging

ue.log('info')
ue.log_warning('warning')
ue.log_error('error')
ue.print_string('on screen')

Threads

Threads work, but only touch uobjects from the game thread.

More