AGameModeBase::MustSpectate
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: UFUNCTIONBlueprintNativeEventconst
Description
Returns true if the given player is only allowed to join as a spectator. The default implementation checks `bOnlySpectator` on the PlayerController.
Caveats & Gotchas
- • This is checked inside `HandleStartingNewPlayer` — returning true causes the player to remain a spectator even if `bStartPlayersAsSpectators` is false.
- • The C++ override must be named `MustSpectate_Implementation`. The non-suffixed function dispatches to it.
- • Returning true here does not automatically place the player in a spectator pawn; you must call `SpawnSpectatorPawn` (or let the engine do it through normal flow). Returning true only prevents `RestartPlayer` from being called.
Signature
ENGINE_API bool MustSpectate(APlayerController* NewPlayerController) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| NewPlayerController | APlayerController* | The newly joined player controller to evaluate. | — |
Return Type
bool Example
Force late-joining players to spectate C++
bool AMyGameMode::MustSpectate_Implementation(APlayerController* NewPlayerController) const
{
// After the match starts, late joiners can only spectate
if (bMatchHasStarted)
{
return true;
}
return Super::MustSpectate_Implementation(NewPlayerController);
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?