Skip to content

Spawning and finding actors

How do I spawn an actor, find actors, or trace a ray?

Spawn

turret = ue.spawn_actor(Turret, ue.Vector(0, 0, 100), health=50)
turret = ue.spawn_actor(Turret, rotation=ue.Rotator(0, 90, 0), owner=player)

spawn_actor(cls, location=None, rotation=None, *, world=None, owner=None, **properties). The world defaults to ue.get_world() (the game or Play In Editor world, else the editor world). Property keywords are set before the actor finishes spawning, so they are in place for begin_play. Only reflected properties are accepted.

Other objects

obj = ue.new_object(MyObject, some_property=1)
mesh = ue.load_object("/Engine/BasicShapes/Cube.Cube")

ue.find_object(path) looks for an object already loaded.

Find actors from gameplay code

coins = ue.GameplayStatics.get_all_actors_of_class(Coin)
enemies = ue.GameplayStatics.get_all_actors_with_tag("enemy")

Trace a ray

hit = ue.line_trace(None, start, end)            # None: ue.get_world()
if hit is not None:
    actor, component, location, normal, distance = hit

It returns None on a miss, else a tuple (actor, component, location, normal, distance). Locations are plain (x, y, z) tuples. ue.line_trace_batch(world, [(start, end), ...]) traces many segments in one call.

Logging

ue.log("message")            # also ue.warning(...), ue.error(...)