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?
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.
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?
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++).
At begin play, get GameMode → RegisterManager(self)
How to set manager references to spawnPoints on the map.
Open up your map
Select your manager
Go to detail and add array elements
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.