How to get selected objects in editor?

I want to capture the mouse click events and get the selected actor inside editor, and do some stuff, but I can’t find the information about this.

I found there is a keypress event inside AActor, but I would also want the event which will get called even if nothing is being selected

there is a bool value “IsSelected” which is an editor property which indicates if this actor is selected in the editor…

USelection* SelectedActors = GEditor->GetSelectedActors();
TArray<AActor*> Actors;
TArray<ULevel*> UniqueLevels;
for (FSelectionIterator Iter(SelectedActors); Iter; ++Iter)
{
AActor
Actor = Cast(*Iter);
if (Actor)
{
Actors.Add(Actor);
//UniqueLevels.AddUnique(Actor->GetLevel());
}
}

This is a code snippet from Unreal Editor Source. This is how they are doing it.

1 Like