Get All Actors of Class fails in Sublevel without a Delay!

STEPS:

  1. Create a MainMap (This will be the persistent map)
  2. Create a SubMap (This is added to the persistent map - MainMap)
  3. Add an input event to the MainMap that will load and set visibility (true) of the “SubMap”
  4. Create a new BP Actor named A
  5. Create a new BP Actor named B
  6. In A’s Event Graph have Event Begin Player call “Get All Actors of Class” and search for class “B”, then print the length of the array.
  7. Put A and B into the SubMap.
  8. Run, use the input key to load the SubMap; the result printed out is 0. (But we know the actor exists!)
  9. Now add a Delay (0.2) node to the beginning of the A’s Event Begin Play (The rest the same as before).
  10. Run, use the input key to load the SubMap; the result printed out is 1. (It works.)

CAUSE?

I believe the cause is because actors in sublevels have their event begin play run as they are instantiated. This feels like a bug, because shouldn’t all actors be loaded from the sublevel before calling beginplay on the actors within? I feel like behavior should be the same in persistent maps and sub maps at least in this regard.


THE PROBLEM

The delay node fixes it but that means you have 0.2 seconds before your actor initializes, and this means your actor is already ticking. So that means you need to be checking for valids all over the place!


SIDE NOTE

The actor A from the sublevel WILL detect all actors B in the persistent world. But again, this isn’t useful if the actors you need are in the sublevel your loading!

Hi Mercurial Forge,

This is expected behavior. The BeginPlay functionality is run as soon as the actor is created. Because the actors are all being generated at roughly the same time, the other blueprints do not technically exist when the “Get all actors of class” is run. The proper way to do this is as you have listed, I would add a delay with an extremely small value (such as .05) that would be unnoticeable but allow the functionality to occur as intended.