So this might be a silly way to do it, but I’m curating all of my world logic actors (like the dialogue and UI managers) that need to always exist in the level by spawning them directly in the GameMode blueprint. The problem with this approach is that as far as I can tell, character controllers’ execute begin play before the gamemode does, so I’m in a situation where character blueprints are searching for the logic actors milliseconds before they appear, then returning null. Is there any way I can guarantee that the logic stuff is spawned before anyone else’s begin play executes, or is the game mode simply the wrong place to do this kind of thing?
The game world, on receiving BeginPlay, takes all it’s levels and broadcasts BeginPlay to all its actors at same time.
If you need a Controller actor to wait for the GameMode, you can simply attach a Delay(0.1) node as first node from Controller’s BeginPlay; then GameMode’s BeginPlay will happen before Controller’s.
Huh, that’s weird, so even though the GameMode is the one broadcasting BeginPlay, its own version executes later?
The problem with using a Delay node is that none of my other stuff is in blueprint; the functions that try to get a reference to the logic actors are all in some ACharacter::BeginPlay() function, and I’d rather not rely on a timer if there’s a way to cement the order of execution in some way- I guess there’s nothing guaranteed to execute just before, or just after BeginPlay?
GameMode doesn’t broadcast BeginPlay, it calls InitGame(); and then InitGameState(); which you can override.
BeginPlay happens whenever an Actor is instanciated, not just when game begins.
Oooh that works, and makes much more sense to boot- thank you!
I am suuuper late to this question. But one of the things I did is, in my custom character I check if my dependency actor has already been initialized and if it has not then I initialize it. For example, I want AWorldSet actor to have its BeginPlay executed before APSCCharacter is done with its begin play. So I do this APSCCharacter’s BeginPlay
void APSCCharacter::BeginPlay()
{
Super::BeginPlay();
AActor* worldSet;
// Iterate through UWorld to find the object, worldSet
if (!worldSet->HasActorBegunPlay())
{
worldSet->DispatchBeginPlay();
}
// Do dependent logic here.
}
Note this only calls BeginPlay for world set once. So you don’t have to worry about being play being called twice. Once this execution is complete world set’s HasActorBegunPlay() will return true preventing further execution of BeginPlay in the same frame.
Hope that helped!