AGameModeBase::SpawnPlayerController
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Spawns and returns the appropriate PlayerController for the joining player, split out from Login() for easier overriding. Override this to conditionally spawn specialized PlayerController subclasses.
Caveats & Gotchas
- • There is a deprecated overload taking SpawnLocation and SpawnRotation (marked UE_DEPRECATED since 4.20) that still exists in the header. When overriding, target the Options-based signature — not the old location/rotation version.
- • Return null only on a genuine error; the engine treats null as a failed login and disconnects the player. Always log the failure reason before returning null to aid debugging.
Signature
ENGINE_API virtual APlayerController* SpawnPlayerController(ENetRole InRemoteRole, const FString& Options); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InRemoteRole | ENetRole | The remote net role for this controller. | — |
| Options | const FString& | URL options string from the joining player. | — |
Return Type
APlayerController* Example
Spawn a spectator controller for players with the spectator URL option C++
APlayerController* AMyGameMode::SpawnPlayerController(ENetRole InRemoteRole, const FString& Options)
{
if (UGameplayStatics::HasOption(Options, TEXT("spectator")))
{
return SpawnPlayerControllerCommon(InRemoteRole,
FVector::ZeroVector, FRotator::ZeroRotator,
SpectatorPlayerControllerClass);
}
return Super::SpawnPlayerController(InRemoteRole, Options);
} See Also
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?