UEngine和Level的Tick函数
函数
void UWorld::Tick( ELevelTick TickType, float DeltaSeconds )
UWorld的pawn成员:
/** List of all the pawns in the world. */ TArray<TWeakObjectPtr<class APawn> > PawnList;
Controller成员ControllerList
/** List of all the controllers in the world. */ TArray<TWeakObjectPtr<class AController> > ControllerList;
SpectatorPawn为我们在edit模式未启动play时使用的pawn(用来控制相机),当我们启动play以后会将我们gamemode指定的pawn添加入world(或叫level)
void UWorld::AddPawn( APawn* Pawn ) { check( Pawn ); PawnList.AddUnique( Pawn ); }
当我们退出game状态回到edit模式则相反
void UWorld::RemovePawn( APawn* Pawn ) { check( Pawn ); AController* Controller = Pawn->GetController(); if (Controller && (Controller->GetPawn() == Pawn)) { Controller->UnPossess(); } PawnList.Remove( Pawn ); }
///////编辑器引擎的Tick函数
void UEditorEngine::Tick( float DeltaSeconds, bool bIdleMode ) { for (auto ContextIt = WorldList.CreateIterator(); ContextIt; ++ContextIt) { FWorldContext &PieContext = *ContextIt; if (PieContext.WorldType != EWorldType::PIE || PieContext.World() == NULL || !PieContext.World()->ShouldTick()) { continue; } TickWorldTravel(PieContext, DeltaSeconds);
} }
的是否打算
void UEngine::TickWorldTravel(FWorldContext& Context, float DeltaSeconds) { if( Context.PendingNetGame ) { Context.PendingNetGame->Tick( DeltaSeconds ); if ( Context.PendingNetGame && Context.PendingNetGame->ConnectionError.Len() > 0 ) { BroadcastNetworkFailure(NULL, Context.PendingNetGame->NetDriver, ENetworkFailure::PendingConnectionFailure, Context.PendingNetGame->ConnectionError); CancelPending(Context); } else if (Context.PendingNetGame && Context.PendingNetGame->bSuccessfullyConnected && !Context.PendingNetGame->bSentJoinRequest && (Context.OwningGameInstance == NULL || !Context.OwningGameInstance->DelayPendingNetGameTravel())) { if (!MakeSureMapNameIsValid(Context.PendingNetGame->URL.Map)) { BrowseToDefaultMap(Context); BroadcastTravelFailure(Context.World(), ETravelFailure::PackageMissing, Context.PendingNetGame->URL.RedirectURL); } else { // Attempt to load the map. FString Error; const bool bLoadedMapSuccessfully = LoadMap(Context, Context.PendingNetGame->URL, Context.PendingNetGame, Error); Context.PendingNetGame->LoadMapCompleted(this, Context, bLoadedMapSuccessfully, Error); // Kill the pending level. Context.PendingNetGame = NULL; } } } }