Software:
Unreal Engine 4.22
This simple Unreal Editor Python example sets the Z axis location of all actors with names beginning with ‘Sphere_’ in a way that their bottom (minimum Z bound) is at height 0.0.
> learn how to run Python scripts in the UE4 Editor
import unreal
from unreal import Vector
lst_actors = unreal.EditorLevelLibrary.get_all_level_actors()
print('place actors at 0 z')
for act in lst_actors:
act_label = act.get_actor_label()
if 'Sphere_' in act_label:
print('placing: {}'.format(act_label))
act_location = act.get_actor_location()
act_bounds = act.get_actor_bounds(False)
act_min_z = act_bounds[0].z - act_bounds[1].z
location_offset = Vector(act_location.x, act_location.y, act_location.z - act_min_z)
act.set_actor_location(location_offset, False, False)
* note that when copying and pasting a script from this example, the indentation may not be pasted correctly.
Note:
The get_actor_bounds unreal.Actor class method returns a tuple object containing 2 unreal.Vector objects, the first being world space location of the actor geometric center, and the second is the corner of the bounding box relative to the center.
‘Sphere_*’ actors before running the script:
‘Sphere_*’ actors after running the script:
Related:
Get started with Python for Unreal Editor
UE4 – Python – Importing assets


2 thoughts on “UE4 – Python – Placing level actors bottom at Z 0.0”