Count objects of a kind

Hi,

I have a level with some blueprint-actors and I want to count them.
How can I do that easily and cheap? Do I have to give them a certain name or so?

Regards
Christian

Hello chricken,

You could use the “Get all actors of class node”. You would then pull off of the array pin and search for “Length”. The number that is returned will be the number of items in the array. The array will be a collection of references to all of the actors of the chosen type. I hope that this helps.

Make it a great day

Thank you,
that worked fine

Hey Rudy, is that really a cheap way? I always read about avoiding “GetAllActorsOfClass”.

My suggestion to chricken would have been to create an Array of that BlueprintActor Type in the GameState class or any other class that is
easily accessible and let the BlueprintActors add themselves to this Array on their BeginPlay.
Then he could get the length of this Array.

Just to avoid the GetAllActorsOfClass node of course.

Is there any real issue with getAllActorsOfClass if you are just doing it once, for most things anyway? It’s the on tick that running this tends to kill things but if you have 20-100 actors in the game surely this doesn’t cause too much of a problem?

True, using it once at begin play or things like that is pretty much ok, but i would like to give people ideas
on how to avoid it completely. Because they may try to use it for more, like checking the number of actors
each time something may have happened to one of them.

I think, having a clean setup for a list that fills and clears itself and is easy to access is better. Just my 2 cents :smiley:

Thank you for your suggestions.
I am using the GetAllActorsOfClass at begin of play and fill a simple integer with it. Each time I collect one of the elements (which is the central part of my game), the counter is being decreased.
Thats very simple and works just fine.

I understand, that counting all objects of a class each and every tick is very expensive, and so I got that idea.
Now I am happy, that an experianced developer has almost the same suggestion.

What I am wondering about just more is the price of the collision-algorithm.
Is it really okay, to have hundrets and hundrets of objects with collisionmesh on the map? Is there any kind of maximum?
But I understand to have to ask that question in a new thread.