Get All Actors in 3D Level
ways to get the list of actors in the current 3D Level / Scene
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:
EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
actors = unreal_systems.EditorActorSubsystem.get_all_level_actors()
A shortcoming of this method, if your work involves Sequencer, is that Spawnables are not included:

Including Sequencer Spawned Actors
This method relies on the fact that Sequencer currently adds a SequencerActor
tag to any actors it spawns:

UnrealEditorSubsystem = unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem)
spawned_actors = unreal.GameplayStatics.get_all_actors_with_tag(
UnrealEditorSubsystem.get_editor_world(),
"SequencerActor"
)
This will give us a list of any spawnable actors which we can add to our earlier results:
EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
UnrealEditorSubsystem = unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem)
def get_all_actors():
actors = EditorActorSubsystem.get_all_level_actors() or []
spawned_actors = unreal.GameplayStatics.get_all_actors_with_tag(
UnrealEditorSubsystem.get_editor_world(),
"SequencerActor"
) or []
return actors + spawned_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

Last updated