AGameStateBase::PlayerArray
#include "GameFramework/GameStateBase.h"
Access: public
Specifiers: UPROPERTYTransientBlueprintReadOnly
Description
The authoritative list of all connected PlayerStates, maintained on both server and clients. PlayerStates are always network-relevant so this array stays in sync automatically.
Caveats & Gotchas
- • Do not add or remove entries manually — use `AddPlayerState` / `RemovePlayerState`. Direct mutation can desync the array from the PlayerState's own back-reference.
- • The array may briefly contain stale entries for players who are disconnecting; always null-check each element before use.
Signature
UPROPERTY(Transient, BlueprintReadOnly, Category=GameState)
TArray<TObjectPtr<APlayerState>> PlayerArray Examples
Iterate all connected players and print their names
Blueprint
Iterate all connected players C++
if (AGameStateBase* GS = GetWorld()->GetGameState())
{
for (APlayerState* PS : GS->PlayerArray)
{
if (PS)
{
UE_LOG(LogTemp, Log, TEXT("Player: %s"), *PS->GetPlayerName());
}
}
} See Also
Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?