UE4 加载地图后的时序
bool UEngine::LoadMap( FWorldContext& WorldContext, FURL URL, class UPendingNetGame* Pending, FString& Error )
{
...
// Prime texture streaming.
IStreamingManager::Get().NotifyLevelChange();
if (GEngine && GEngine->XRSystem.IsValid())
{
GEngine->XRSystem->OnBeginPlay(WorldContext);
}
//调用UWorld的BeginPlay
WorldContext.World()->BeginPlay();
// send a callback message
PostLoadMapCaller.Broadcast(WorldContext.World());
WorldContext.World()->bWorldWasLoadedThisTick = true;
...
}
void UWorld::BeginPlay()
{
AGameModeBase* const GameMode = GetAuthGameMode();
if (GameMode)
{
//调用gamemodebase类的StartPlay()
GameMode->StartPlay();
if (GetAISystem())
{
GetAISystem()->StartPlay();
}
}
OnWorldBeginPlay.Broadcast();
#if WITH_CHAOS
if(PhysicsScene)
{
PhysicsScene->OnWorldBeginPlay();
}
#endif
}
void AGameModeBase::StartPlay()
{ //调用GameState的 HandleBeginPlay()
GameState->HandleBeginPlay();
}
void AGameStateBase::HandleBeginPlay()
{
bReplicatedHasBegunPlay = true;
//调用WorldSetting的NotifyBeginPlay()
GetWorldSettings()->NotifyBeginPlay();
GetWorldSettings()->NotifyMatchStarted();
}
void AWorldSettings::NotifyBeginPlay()
{
UWorld* World = GetWorld();
if (!World->bBegunPlay)
{ //调用World中所有Actor的BeginPlay()
for (FActorIterator It(World); It; ++It)
{
SCOPE_CYCLE_COUNTER(STAT_ActorBeginPlay);
const bool bFromLevelLoad = true;
It->DispatchBeginPlay(bFromLevelLoad);
}
World->bBegunPlay = true;
}
}