RealDocs

AGameModeBase::GetPlayerControllerClassToSpawnForSeamlessTravel

function Engine Since 4.14
#include "GameFramework/GameModeBase.h"
Access: public Specifiers: virtual

Description

Returns the PlayerController class to spawn for a seamlessly traveling player. The default implementation returns `PlayerControllerClass`.

Caveats & Gotchas

  • If the returned class is the same type as `PreviousPlayerController`, `SwapPlayerControllers` is **not** called — the existing PC is reused and only re-initialized via `HandleSeamlessTravelPlayer`.
  • Returning a null class will cause the engine to fall back to the default `PlayerControllerClass`, so a null check in the override is advisable.
  • Override this to spawn different controller classes per-player (e.g. based on a game mode variant stored on the PlayerState).

Signature

virtual TSubclassOf<APlayerController> GetPlayerControllerClassToSpawnForSeamlessTravel(APlayerController* PreviousPlayerController)

Parameters

Name Type Description Default
PreviousPlayerController APlayerController* The player controller from the previous level.

Return Type

TSubclassOf<APlayerController>

Example

Spawn a spectator controller for already-eliminated players C++
TSubclassOf<APlayerController> AMyGameMode::GetPlayerControllerClassToSpawnForSeamlessTravel(
    APlayerController* PreviousPlayerController)
{
    if (PreviousPlayerController && PreviousPlayerController->PlayerState)
    {
        if (auto* MyPS = Cast<AMyPlayerState>(PreviousPlayerController->PlayerState))
        {
            if (MyPS->bEliminated)
            {
                return AMySpectatorController::StaticClass();
            }
        }
    }
    return Super::GetPlayerControllerClassToSpawnForSeamlessTravel(PreviousPlayerController);
}

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.