RealDocs

UGameplayStatics::GetPlayerState

function Engine Blueprint Since 5.1
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticBlueprintPure

Description

Returns the APlayerState at the given index in the game state's PlayerArray. The index is consistent across client and server after initial replication.

Caveats & Gotchas

  • Returns null for an out-of-range index without asserting — always validate the index against GetNumPlayerStates() first.
  • Index ordering is determined by the server and replicated; it is stable during a session but not guaranteed to be the same between different game sessions or after reconnection.
  • UnsafeDuringActorConstruction: GameState (and thus PlayerArray) may not be initialized yet.

Signature

static ENGINE_API class APlayerState* GetPlayerState(const UObject* WorldContextObject, int32 PlayerStateIndex);

Parameters

Name Type Description Default
WorldContextObject const UObject* Object used to retrieve the world context.
PlayerStateIndex int32 Index into GameState::PlayerArray. Valid range: 0 to GetNumPlayerStates()-1.

Return Type

APlayerState*

Example

Display names of all connected players in the HUD C++
int32 Count = UGameplayStatics::GetNumPlayerStates(this);
for (int32 i = 0; i < Count; ++i)
{
    APlayerState* PS = UGameplayStatics::GetPlayerState(this, i);
    if (PS)
    {
        HUD->AddPlayerEntry(PS->GetPlayerName(), PS->GetScore());
    }
}

Version History

Introduced in: 5.1

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.