GetAllActorsOfClass and GetSelectedActors in Editor Utility Widget seems to returns actors data differently

Hi everyone,

I’m creating an Editor Utility Widget to display a list of actors of a specific class or implementing a specific interface, and show some information related to them (the actual implementation is not important).

The problem comes when I need to read that information. To get access to the actors, I’m currently using this:

TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), FoundActors);

But I retrieve no information.


The blue is the list of objects I want to read the information, but it’s empty. The Red are some variables I exposed to better some of the info I need.

However, if I use the selected actor method with this code:

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

I get all the info I want.


I used the same workflow as before, but here I have everything I want.

Honestly, I can’t figure out why this is happening. For more context, I’m executing an Editor Utility Widget from a Toolbar button in a PIE session since it’s during game time that the information I need is available.

Do you know why this is happening and how I can fix it? I basically need a way to get all the actors I need in the level.

Thank you in advance to everyone :+1:.

Problem solved!

I was digging around the GEditor pointer when I came across a variable called TObjectPtr<class UWorld> PlayWorld. When I checked it out in debug mode, I found all my actors there, with all the right info.

So, I updated my code to this:

TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GEditor->PlayWorld, AActor::StaticClass(), FoundActors);

I have some ideas about why GetWorld() doesn’t give back as much info as GEditor->PlayWorld when used in an Editor Utility Widget window, but I’m not 100% sure.

If anyone knows more about this, I’d love to hear their thoughts. :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.