ways to get the list of actors in the current 3D Level / Scene
Last updated
Something that isn't entirely apparent in Unreal, especially if your work involves Sequencer, is that the obvious function to get all levels in the current Editor World isn't always enough to get every actor in the viewport.
For Persistent Actors
The most basic function to get the available actors in our 3D Level is get_all_level_actors:
This updated function will successfully find the Spawnable Actor:
Expanded Options
From a pipeline perspective we might want the ability to separate Spawnable (Sequencer) actors from Possessable (Persistent Level) actors. This convenience function supports each posibility:
EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
UnrealEditorSubsystem = unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem)
def get_all_actors(include_possessables = True, include_spawnables = True):
"""
Get the list of Actors in the current Editor World / 3D Level
parameters:
include_possessables (bool): whether to include Persistent Level actors
include_spawnables (bool): whether to include Sequencer Spawned actors
"""
actors = []
if include_possessables:
actors += EditorActorSubsystem.get_all_level_actors() or []
if include_spawnables:
actors += unreal.GameplayStatics.get_all_actors_with_tag(
UnrealEditorSubsystem.get_editor_world(),
"SequencerActor"
) or []
return actors