* Why * is Get All Actors of Class not performant?

Is it because it has to scan all actors to find the class you’re requesting?

Or is it because it has to scan through all the items in the class you’re requesting?

I guess another way to frame this question would be ‘Is it more reasonable to use GAAOC when you know you’ll only have a single matching actor as opposed to hundreds?’ Or would the performance cost of the function be the same, regardless?

GAAOC iterates over a hash of actors of that class, so does not start with all classes.

Since UE4 you’ve been able to use ‘get actor of class’ to zoom in directly on something you know there’ll only be one of.

Still, neither is a good idea on tick, of course.

Personally, I don’t think there’s anything wrong with it when used carefully, just like tick. But some people will weaponize any node you give them :slight_smile:

5 Likes

Perfect! That’s exactly what I wanted to know, thank you!

2 Likes

Absolutely no harm if you assign a reference once you have it. Avoids a lot of unnecessary hassle.

Interesting… so I’ve actually been learning about reference optimization a lot lately.

Are you saying that because the GAAOC function creates a hard reference itself(?), why not? Because once you’ve used GAAOC, there’s no additional ‘reference cost’ to store the results as a variable?

Yup. It’s a pity soft class refs don’t work in 5. Not in BP anyway…

3 Likes

It’s actually not that bad from a performance perspective, I thought it would iterate through all actors in the world, but nope, it uses the hash to severely limit the amount of actors it needs to iterate over.

That said, the use of the node should still never be a requirement to get the references. Maybe if you have a novel use-case to do some one-off behavior I can see justifying the use of the node, but otherwise, I’d just manage the references.

If you’re using the node because you don’t know how to otherwise get the references, you should really learn to manage references. Once you know, then you should also have a feel for when you really should be managing your references.

3 Likes

You’ll probably see a lot of it from me, for two reasons

  1. It’s fine for someone whose very early in the learning cycle. They just want to get something working.

  2. It’s a lot easier than trying to explain how references work to a newbie

:wink: