TActorRange to get all actors of class?

When Sam said we’re going to get all the controllers and he wrote, TActorRange<AController>(GetWorld()) it did not seem intuitive to me.

I looked in the source code, at the documentation, I googled, and I asked ChatGPT. UGameplayStatics::GetAllActorsOfClass() or the like is common. GetAllActorsOfClass() is intuitive. I believe the TActorRange is lighter and what should be used, I think. I understand that it iterates over all the AController instances and their children in the game world.

My question is, how does someone even find out about TActorRange? It makes me want to look up every class in EngineUtils to see what I’m missing out on. Did you know about TActorRange? How did you find out about it? How do you think most people discover it?

It’s lighter in the sense that it doesn’t dynamically allocate memory. If you need to hold an array of them to do something with them later then that’s fine but here we just want to do something with them as we iterate and that’s it.

This is unfortunately one of the things that aren’t documented well. It is something you find out about in example projects (or in this course).

2 Likes

Good point. I’m going to read more code in example projects. I’ve done some of that when I first started, but my understanding of UE cpp was not at a point that it was productive. That’s changed and I’ll revisit reading other’s code.

1 Like

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

Privacy & Terms