Cast To vs Get All Actors Of Class

I feel quite confident using only blueprints now, but one thing that consistently eludes my understanding is when to use casting vs the “get all actors of class” nodes. For some reason, in some cases, only one or the other works (usually calling an event or function or getting a variable from another blueprint). I watched the recent blueprint support stream but they didn’t cover the differences between casting/get all actors of class, so I would love if someone could quickly explain when you should use one over the other, and which are less performant (I’m assuming the “Get all actors of class” node is less performant since it makes an array of everything in the blueprint).

Thanks!

Get all actors of class gets all of actors of a certain class in the LEVEL, not on the blueprint. From the blueprint you already have access to its components directly. Plus, Get all actors of class is sorta expensive because it loops through all the actors in the level and depending on how many there are, you shouldn’t use this node all the time as it might hinder your game’s performance.
Casting just checks if an actor reference is of a certain class, if it is, you can get its properties. If it isn’t, it fails and you can do something from there. Basically, Get all actors of class just does “loop through all actors in the level” + “Cast to CLASS” and puts them in an array.

Thank you for this! I found that for finding waypoints in a level, I had to use “Get all actors of class” but for calling functions I could just cast directly- this clears things up! Thanks for the help!

There is also a node called “Get Actor of Class” that doesn’t return an array, but the specific actor you specify. I, too, sometimes wonder why both exist. Sometimes, I even have to get an actor of class just to create the object wildcard for a cast, and subsequently get a warning that the cast is redundant. So I then promote the return value to a variable, and change the variable type to an object reference of whatever class is being cast to. It doesn’t feel right. And, it seems more expensive than it ought to be, because I have to use a Begin Play to set the variable in the first place in order for it to work.