I’m pretty new to Seamless Travel. We need to do some initialization on our PlayerController class when it loads a new level. BeginPlay() doesn’t get called because the actor wasn’t ever considered to have ended play. Is there some kind of equivalent to BeginPlay() when a new world is loaded when using Seamless Travel?
My first thought was to try overriding NotifyLoadedWorld(), but when that’s called no actors have replicated, and I need access to the GameState to do my initialization.
Currently, I’m looking at:
Overriding ReceivedGameModeClass() in my PC, but that seems a bit… obscure.
Having my GameState’s HandleMatchIsWaitingToStart() call a custom initialization function in my PlayerController class. That’s what calls BeginPlay() on everything else on each level load.
Thinking the latter is probably the best idea. I was just wondering if I was missing an existing solution, plus I wanted to get thoughts from folks who know more about Seamless Travel than I do.
Don’t know if youv’e figured out a solution for this, but I found the following functions in PlayerController:
NotifyLoadedWorld(FName WorldPackageName, bool bFinalDest)
and
void ServerNotifyLoadedWorld(FName WorldPackageName)
You can use it to inform your traveled client that they have arrived at the destination map and need to re-start, but you will still need have some signal from the gamemode\gamestate to let you know that everybody else has shown up.
Implementing AGameModeBase::HandleStartingNewPlayer_Implementation seems like the best solution if you have common needs whether at first level loading and after a server travel, as it is called in each of these scenarii.
If your need is specific to seamless travel, overriding AGameModeBase::InitSeamlessTravelPlayer or AGameModeBase::HandleSeamlessTravelPlayer would fit.
In both of these cases you should call the parent method before your implementation.
InitSeamlessTravelPlayer is called right after controller re-creation,
HandleSeamlessTravelPlayer is the one calling it, so after the parent call the controller is initialized and went through HandleStartingNewPlayer.
FYI - you can use APlayerController::PostSeamlessTravel() this will get called everytime your player transitions to a new map via seemless travel.
/**
* Called after this player controller has transitioned through seamless travel, but before that player is initialized
* This is called both when a new player controller is created, and when it is maintained
*/
ENGINE_API virtual void PostSeamlessTravel();