APlayerState::IsSpectator
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: UFUNCTIONBlueprintGetter
Description
Returns whether this player is currently spectating rather than actively playing.
Caveats & Gotchas
- • IsSpectator (bIsSpectator) is distinct from IsOnlyASpectator (bOnlySpectator) — bIsSpectator is a transient flag toggled as players enter/exit spectator mode during a match, while bOnlySpectator means the player can never become an active participant.
- • This flag is replicated so it is safe to read on clients, but there will be at least one replication round-trip of lag after the server toggles it.
Signature
bool IsSpectator() const Return Type
bool Example
Filter spectators from active player list C++
TArray<APlayerState*> ActivePlayers;
for (APlayerState* PS : GameState->PlayerArray)
{
if (!PS->IsSpectator())
{
ActivePlayers.Add(PS);
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?