How do I know when I can get actors from a dynamic level instance?

I have this blueprint here:

This is a simple version of what I am trying to do with level instance actors to generate a level at the start of the game.

I load a level instance, and when the level is loaded, I am trying to get spawn points that lie in the level, NewMap. However, the length of the array is always 0.

I can add a delay, but the amount of delay needed seems inconsistent, which is not ideal. I need to get all spawn points in the entire map AFTER all level instances have loaded in, so that I can plan out my item spawns depending on how many spawn points exist.

How do I guarantee that all level instances have finished loading AND the actors within it are able to be grabbed, or have begun play?

Try “Bind On Level Shown” instead. It’s after actors construction and before begin play.
image

The same issue occurs with the On Level Shown event… I am not sure when actors can be retrieved through Get All Actors of Class but it may be after that actor has begun play.

Then you have to do it another way. I am doing instanced level in a multiplayer project but it should be the same process.
image
At your BP’s Begin Play, do register BP to something accessible across level instance like GameState, GameInstance, PlayerController or PlayerPawn.


I have a manager that has an array of references to all spawn points on the level. This way I don’t have to do get all class of type which may be expensive. Each level instance should only have 1 manager so each time a manager registers you’d know a level has done loading.

I tried having the spawn points subscribe to a manager in the GameMode but I ran into the same issue with GetAllActorsOfClass where the level instance would “finish loading” and run the callback, but the spawn points in that level instance have not begun play or added themselves to the manager yet.

Just to make it clearer for me, in your version, you have a spawn manager for each individual level instance which registers itself to a higher-level manager? Does the manager register itself on begin play? Is it safe to assume that once that manager has registered itself that all spawn points in that level instance are available, at least on next tick?

try using GetAllLevelActors and filter your bp spawn points from it.
Docs: Get All Level Actors | Unreal Engine 5.2 Documentation

Target is Editor Level Library

I can’t use editor subsystems in a packaged game, so this won’t work unfortunately.

SpawnPoint:
The points themselves don’t do anything.

GameMode:
Have an array of Managers as a variable.
Make a function call RegisterManager(Manager& manager) that add the manager to your array.

Manager:
Have an array of spawnPoints as a variable and make it Instance Editable(BP) or EditAnywhere(C++).
image
image

At begin play, get GameMode → RegisterManager(self)

How to set manager references to spawnPoints on the map.

  1. Open up your map
  2. Select your manager
  3. Go to detail and add array elements
  4. Set each index to a spawnPoints

I do this route to get all references to actors on the level instance. You can give each manager an ID so you can differentiate levels by manager’s ID.

Thanks! I totally get it now. That’s a good way to make sure all actors of the manager actually exist.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.