Python: Placing actors based on height of other actors

Hello AirLea,

best thing would be to do a top down line trace (on complex collision) from above the location you want to test in x,y. Something like

import unreal

sm = unreal.EditorAssetLibrary.load_asset("/game/SM_StaticMeshToSpawn")

world = unreal.EditorLevelLibrary.get_all_level_actors()[0].get_world()
posToTest = unreal.Vector(0,0,0)

listOfObjectTypeQuery = unreal.Array(unreal.ObjectTypeQuery)
listOfObjectTypeQuery.append(unreal.ObjectTypeQuery.OBJECT_TYPE_QUERY1)
listOfObjectTypeQuery.append(unreal.ObjectTypeQuery.OBJECT_TYPE_QUERY2)
hit = unreal.SystemLibrary.line_trace_single_for_objects(world,unreal.Vector(posToTest.x,posToTest.y,500),unreal.Vector(posToTest.x,posToTest.y,0),listOfObjectTypeQuery,True,unreal.Array(unreal.Actor),unreal.DrawDebugTrace.NONE,True)
if hit != None:
    print(hit)
    print(hit.to_tuple())
    print(hit.to_tuple()[4])
    print(hit.to_tuple()[5])#impact_point
    print(hit.to_tuple()[6])
    unreal.EditorLevelLibrary.spawn_actor_from_object(sm,hit.to_tuple()[5])

I am not so sure about the Object_Type_Query as I do not get the real Enum values and reading the hitresult is not so great either, but that should work.

In that sample I am assuming the origin of my mesh is in z = 0, else you will have to add the delta between origin of your mesh and its lowest point.

1 Like