Python scripts
import unreal
print(f'UE version {unreal.SystemLibrary.get_engine_version()}')
import unreal
editor_actor_subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
all_actors = editor_actor_subsystem.get_all_level_actors()
print(f"Found {len(all_actors)} actors in the scene:")
for actor in all_actors:
if actor:
print(f"- {actor.get_name()} ({actor.get_class().get_name()})")
else:
print(f"- [Invalid actor]")
import unreal
import random
x = random.uniform(-500.0, 500.0)
y = random.uniform(-500.0, 500.0)
z = random.uniform(0.0, 500.0)
sphere_location = unreal.Vector(x, y, z)
actor_class = unreal.StaticMeshActor
spawned_actor = unreal.EditorLevelLibrary.spawn_actor_from_class(
actor_class, sphere_location, unreal.Rotator(0.0, 0.0, 0.0)
)
if spawned_actor:
sphere_mesh = unreal.load_asset('/Engine/BasicShapes/Sphere.Sphere')
if sphere_mesh:
static_mesh_component = spawned_actor.get_component_by_class(unreal.StaticMeshComponent)
if static_mesh_component:
static_mesh_component.set_static_mesh(sphere_mesh)
print(f'Sphere spawned at {sphere_location}')
else:
print('Error: Could not find StaticMeshComponent on spawned actor.')
else:
print('Error: Could not load /Engine/BasicShapes/Sphere.Sphere')
else:
print('Error: Failed to spawn StaticMeshActor.')
Last updated