Ue4 count all actor of a class

how can i have a number in my widget of how mush wolf are there in the level like if have 7 wolf in this level i want it to show a numer that says 7

Here are two methods to find the number of actors of a particular class:

  1. Get All Actors of Class → returns an array of all the actors of a particular class. you can then get the array length to find the number of actors.
    Cons : it’s kinda expensive :warning:, so only use it once like in Event Construct or BeginPlay and avoid using it in Tick

  2. If you’re spawning the actors at runtime, you can add the actor references to an array when you spawn them and get the length of the array to get the number of actors.

I recommend using the seconds method.

If you don’t need to store references to the spawned actors, you can use an Integer variable instead of an array and add 1 to the integer everytime you spawn an actor and subtract 1 when you destroy it.


1 Like