RealDocs

AGameStateBase::AddPlayerState

function Engine Since 4.14
#include "GameFramework/GameStateBase.h"
Access: public Specifiers: virtual

Description

Adds the given `APlayerState` to `PlayerArray`. Called automatically by the engine when a player connects; you would only call this directly if managing player states manually.

Caveats & Gotchas

  • The engine calls this for you on connection. Calling it again for the same `PlayerState` will add a duplicate entry — the base implementation does not guard against duplicates.
  • Override this (calling `Super`) if you need to maintain a separate data structure (e.g. a TMap keyed by player ID) that mirrors `PlayerArray`.

Signature

ENGINE_API virtual void AddPlayerState(APlayerState* PlayerState)

Parameters

Name Type Description Default
PlayerState APlayerState* The player state to add to `PlayerArray`.

Return Type

void

Example

Extend AddPlayerState to keep a score map C++
void AMyGameState::AddPlayerState(APlayerState* PlayerState)
{
    Super::AddPlayerState(PlayerState);
    if (PlayerState)
    {
        PlayerScores.Add(PlayerState, 0);
    }
}

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.