RealDocs

APlayerState::SetIsSpectator

function Engine Since 4.0
#include "GameFramework/PlayerState.h"
Access: public Specifiers: ENGINE_API

Description

Sets the spectator flag on the PlayerState and replicates the change to clients.

Caveats & Gotchas

  • This only updates the flag — it does not change the player's controller state, possession, or camera. Call AGameMode::SpectatorLogin or the appropriate controller transitions alongside this.
  • Server-side only; calling on a client has no networked effect.

Signature

void SetIsSpectator(const bool bNewSpectator)

Parameters

Name Type Description Default
bNewSpectator const bool True to mark the player as spectating, false to mark as active.

Return Type

void

Example

Transition a player to spectator mode mid-match C++
void AMyGameMode::MovePlayerToSpectators(APlayerController* PC)
{
    if (APlayerState* PS = PC->GetPlayerState<APlayerState>())
    {
        PS->SetIsSpectator(true);
    }
    PC->StartSpectatingOnly();
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.