RealDocs

AGameModeBase::GetNumSpectators

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

Description

Returns the number of human players who are currently spectating. Distinguishes observer-only connections from active participants.

Caveats & Gotchas

  • Server-only — GameMode does not exist on clients, so this always returns 0 there.
  • A player that is between respawns and temporarily assigned a spectator pawn may or may not be counted here depending on the subclass implementation; verify with AGameMode if you use match-state spectating.

Signature

UFUNCTION(BlueprintCallable, Category=Game)
virtual int32 GetNumSpectators()

Return Type

int32

Example

Show spectator count in a log C++
UE_LOG(LogTemp, Log, TEXT("Players: %d  Spectators: %d"),
    GetNumPlayers(), GetNumSpectators());

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.