[BP] How to use SpawnActor from a class that's not in the game world

Hey there UE4 pals!

I have an code architecture question for BP. I’m currently working on mission system using data a table. I’m also deciding to spawn triggers for these missions from a table as well. So missions will reference a spawn triggers for completion. I’m currently creating the trigger manager to spawn trigger boxes based on which missions the player has accepted.

I’ve seen demo projects that make these type of managers actors that they place in each level, but I’m convinced there must be a more appropriate way to handle this. I’ve tried having the mission manager inside of the Game Instance or Game Mode, but calling the SpawnActor from these blueprints causes the following error:

UGameplayStatics::BeginSpawningActorFromClass: TriggerBox_BP_C can not be spawned in NULL world

Which makes sense since there’s both the Game Instance and the Game Mode doesn’t have a world reference. Is there an alternative solution or shall I resort to making my managers place-able actors?

Thank you for any suggestions or thoughts in advance! :slight_smile:

Using game instance or game mode will not work, since there is no world yet, but you may have the player pawn or the player controller which can spawn that class you want.

Also you may use the Level Blueprint to spawn that manager.

In my case i have created a dynamic loader, which is an actor placed on level, and I have the spawner, which is the location where I want my actor to spawn, so everytime the spawner runs the “Begin Play” it will look up for the first dynamic loader actor on map and use it to check what it’ll load and if it can be loaded.

Hey Victor, it’s good to know that was helpful!

I am also concern about the organization and the fact to make it the more automatized I could so the level designers won’t need to care much about it!

I usually tends to use the game mode for game logics, in my case, that won’t make sense to have it, since the loader is based on the level itself and not on the game mode. But since your case seems to be about the game mission, I believe that will make perfect sense to have it spawned on Game Mode

Hey lotti! Thanks for the quick reply!

My thinking behind putting it in the game instance or mode, was to first prevent the upkeep of additional programming effort within each new level - that is having to manually place down a manager every level or having to write new code to them as more levels are made. While the level blueprint doesn’t fix that concern, the Player Character and Controller do; though I don’t like idea of having either of them tied with dynamic trigger spawning - doesn’t make organizational sense me thinks.

I was thinking of a similar solution to your dynamic loader except I was going to call it Manager Handler - basically an actor that will be responsible of loading my managers since I will have more than just the trigger manager. But I think it makes more sense to do what you’re doing and just create a general dynamic loader as you call it. At least that way if I’m going to put anything (including managers) in the game world, it will only be one instance of a blueprint that I will have to place down per level. Thank you so much for giving me your insight on this, it’s certainly giving me better ideas on how to handle this.

Also, I just remembered that the Game Mode does spawn the player character, so it should be able to spawn my triggers. It just didn’t because my TriggerManager class extends from object instead of an actor. But if I put the same logic directly on the Game Mode, it works fine!