AGameStateBase::SpectatorClass
#include "GameFramework/GameStateBase.h"
Access: public
Specifiers: UPROPERTYTransientBlueprintReadOnlyReplicatedUsing=OnRep_SpectatorClass
Description
The pawn class used for spectating, assigned by GameModeBase and replicated to all clients so they can spawn the correct spectator pawn when entering spectator mode.
Caveats & Gotchas
- • On clients, this value is only valid after `OnRep_SpectatorClass` fires — do not assume it is set during early `BeginPlay`.
- • The PlayerController uses this class when calling `SpawnSpectatorPawn`; overriding it without also customizing `AGameModeBase::SpectatorClass` can leave the two out of sync on listen servers.
Signature
UPROPERTY(Transient, BlueprintReadOnly, Category=GameState, ReplicatedUsing=OnRep_SpectatorClass)
TSubclassOf<ASpectatorPawn> SpectatorClass Example
Read spectator class on a client C++
if (AGameStateBase* GS = GetWorld()->GetGameState())
{
TSubclassOf<ASpectatorPawn> SpecClass = GS->SpectatorClass;
UE_LOG(LogTemp, Log, TEXT("Spectator class: %s"), SpecClass ? *SpecClass->GetName() : TEXT("none"));
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?