I need selecting actor that has specific instanced mesh and I implement like below.
UEditorActorSubsystem* EditorActorSubsystem = GEditor->GetEditorSubsystem<UEditorActorSubsystem>();
if (!ensure(IsValid(EditorActorSubsystem)))
{
return;
}
bool bEscape = false;
TArray<AActor*> SelectedActors;
for (AActor* Actor : EditorActorSubsystem->GetAllLevelActors())
{
TArray< UInstancedStaticMeshComponent*> InstantcedComps;
Actor->GetComponents(InstantcedComps);
for (UInstancedStaticMeshComponent* InstancedComp : InstantcedComps)
{
for (int i = 0; i < InstancedComp->GetInstanceCount(); ++i)
{
if (InstancedComp->IsInstanceSelected(i))
{
SelectedActors.Emplace(Actor);
bEscape = true;
break;
}
}
if (bEscape)
{
break;
}
}
bEscape = false;
}
if (SelectedActors.IsEmpty())
{
return;
}
GEditor->SelectNone(true, true);
for (AActor* Actor : SelectedActors)
{
GEditor->SelectActor(Actor, true, true, false, true);
}
UInstancedStaticMeshComponent has function that check if specific instance is selected.
In small level it works fine, but I need use it in level that has million actors.
In implementation above check every actors in level, so it takes much longer I need.
Is there more effecient way to do it?