How can I get the actor count in a level?

Hi,

I have a quick question: is there a way to get the number of times I placed a specific actor in my level?

I’m asking because I want to create a Debugger actor that will check on BeginPlay whether it is the only instance of that actor in the level. Having more than one Debugger would start conflicting with some functionality, so I wanted to add a system that would warn me if I accidentally did such a thing so I could remove the excess of instances of the Debugger actor.

Thanks,
Shrooblord

In Blueprint, there’s a node called “Get all actors of class”. It returns an array. Just read that array’s Length, that’s how many instances of that actor’s class there are in the world.

If you want to do this in-editor, this might help. Same idea would work at runtime I think,but not sure of your circumstances.

https://answers.unrealengine.com/questions/77282/how-do-i-show-info-about-level-setup-in-editor.html

For some reason this method isn’t working. Although I’m following a tutorial and do exactly as he does but for me it doesn’t work. The variables always return 0 value. I am on 4.6 by the way

Did you remember to select the correct class for the “get all actors of class”?

I mean are you really sure it’s the right one?

yes, I have only 2 classes to chose from :slight_smile:
It might be a bug

Could you show us your setup please?

(Just a short screenshot from the BP). It should make it quite a lot easier to tell where something doesn’t work as expected :wink:

Hope you find the problem.

Just to make sure, your actors are manually placed in the level and not created on level load, right?

Try using the “event begin play” in the event graph.

The construction script does things before the actual actor or game mode in this case exists. That’s why self references will fail here as well.

Since the game mode is the primary BP it might just construct it before the level is loaded fully.

Event begin play well trigger as soon as the game begins. Either when the first cut scene runs out as soon as the player can do something or as soon as the actor which uses this event starts to actually exist.

Cheers

I don’t understand! Begin Play to do what? counting all actors of class in the level?

please stop spamming this. It’s not helpful and more complicated than it supposed to be.

yes manually

He means put all those nodes after the Event Begin Play in your MyGame Event Graph instead of on the construction script, because the construction script is run before your actors are loaded in the level (even if they are manually placed).

You can check in the GameMode bp , in which use “Get all actor of class”.Do NOT use the construction script to implement this.Implement it in the Event Graph using Event Begin Play.Example .

2 Likes

hey check my answer ,if u have not found solution yet

Hey. It worked for me. Thanks

Hey. It worked for me. Had to read fev comments below to get what you mean… :wink:

This comment chain correctly displays the answer, but I accepted PoroKin’s reply since he shows it in working order within the first reply. Thanks, though, guys.