How can I know when all of my actors are ready?

I have a bunch of actors with static mesh components. At runtime I iterate through these and replace them with instanced static meshes. The problem is that I need to know when all of the actors are ready to be scanned, but I don’t know how many there are, so I can’t count them coming in or anything. I need to know they’re ready before the server can allow all players to start the game.

What’s the Unreal way to solve this problem?

This is chicken and egg problem, or load order.

It is more to this than you would think. You have actors that you never know in which order are loaded. It is not guaranteed that they will be loaded same way in published game, or standalone or on different platforms. So be careful do not use and hax trick for that.

Only way to know it is to count them.

Simple solution:

  • in something persistent on server go get all actors of class and count them. I usually use GameMode, but that is for singleplayer games. Pick your own poison here.
  • then in each actor on begin play tell that persistent class on server that one more is spawn, so decrease counter.

But above solution is probably not what you really need. At some point you will want widgets to be displayed with info about those actors, or count score, etc. So probably more complicated system is needed.

That persistent actor of your choice needs blueprint interface, and function that registers spawned actors. Then either count them and do not start match until they all are registered.

Or. make countdown for match to start (like it was in old UT99). Usually after 0.2 sec delay everything is loaded, but this is exactly hax trick i do not advise.

Use Inheritance for those actors, ie. make parent class that registers and hooks dispatchers etc. Then create child class for rest of functionality. It is more flexible, and as bonus you will know hat code is where, so it is easier to maintain.

I was recently fighting such problem, ie. spawning actors during begin play, together with widgets communication, it is a mess in unreal (or i think in any OOP code that loads objects during runtime).

You pretty much nailed it all. I didn’t think to count the actors on the server and relay that to the clients; I suppose the server will have things loaded very early so I can rely on looking for them in the gamemode. Thanks for the ideas