RealDocs

APlayerState::SetIsOnlyASpectator

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

Description

Sets the permanent spectator-only flag, indicating this player can never transition to an active playing role in the session.

Caveats & Gotchas

  • bOnlySpectator is separate from bIsSpectator — setting this flag does not automatically set bIsSpectator; both should normally be set together when creating a dedicated spectator slot.
  • This flag is replicated, but unlike bIsSpectator it is not typically toggled during gameplay — treat it as a session-setup property.

Signature

void SetIsOnlyASpectator(const bool bNewSpectator)

Parameters

Name Type Description Default
bNewSpectator const bool True to permanently mark this player as spectator-only.

Return Type

void

Example

Mark a player as permanent spectator on login C++
void AMyGameMode::InitNewPlayer(APlayerController* PC, const FUniqueNetIdRepl& UniqueId, const FString& Options, const FString& Portal)
{
    Super::InitNewPlayer(PC, UniqueId, Options, Portal);
    if (UGameplayStatics::HasOption(Options, TEXT("spectator")))
    {
        APlayerState* PS = PC->GetPlayerState<APlayerState>();
        PS->SetIsOnlyASpectator(true);
        PS->SetIsSpectator(true);
    }
}

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.