UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
APlayerState Class Reference

#include <PlayerState.h>

+ Inheritance diagram for APlayerState:

Public Member Functions

virtual ENGINE_API void OnRep_Score ()
 
virtual ENGINE_API void OnRep_PlayerName ()
 
virtual ENGINE_API void OnRep_bIsInactive ()
 
virtual ENGINE_API void OnRep_PlayerId ()
 
virtual ENGINE_API void OnRep_UniqueId ()
 
virtual ENGINE_API void PostInitializeComponents () override
 
virtual ENGINE_API void Destroyed () override
 
virtual ENGINE_API void Reset () override
 
virtual ENGINE_API FString GetHumanReadableName () const override
 
APawn * GetPawn () const
 
template<class T >
T * GetPawn () const
 
ENGINE_API class AControllerGetOwningController () const
 
ENGINE_API class APlayerControllerGetPlayerController () const
 
virtual ENGINE_API void ClientInitialize (class AController *C)
 
virtual ENGINE_API void UpdatePing (float InPing)
 
virtual ENGINE_API void RecalculateAvgPing ()
 
virtual ENGINE_API bool ShouldBroadCastWelcomeMessage (bool bExiting=false)
 
virtual ENGINE_API void SetPlayerName (const FString &S)
 
virtual ENGINE_API void SetPlayerNameInternal (const FString &S)
 
ENGINE_API FString GetPlayerName () const
 
virtual ENGINE_API FString GetPlayerNameCustom () const
 
virtual ENGINE_API FString GetOldPlayerName () const
 
virtual ENGINE_API void SetOldPlayerName (const FString &S)
 
virtual ENGINE_API void RegisterPlayerWithSession (bool bWasFromInvite)
 
virtual ENGINE_API void UnregisterPlayerWithSession ()
 
virtual ENGINE_API class APlayerStateDuplicate ()
 
virtual ENGINE_API void OnDeactivated ()
 
virtual ENGINE_API void OnReactivated ()
 
virtual ENGINE_API void SeamlessTravelTo (class APlayerState *NewPlayerState)
 
virtual ENGINE_API void GetLifetimeReplicatedProps (TArray< FLifetimeProperty > &OutLifetimeProps) const override
 
ENGINE_API void DispatchOverrideWith (APlayerState *PlayerState)
 
ENGINE_API void DispatchCopyProperties (APlayerState *PlayerState)
 
float GetScore () const
 
ENGINE_API void SetScore (const float NewScore)
 
int32 GetPlayerId () const
 
ENGINE_API void SetPlayerId (const int32 NewId)
 
uint8 GetCompressedPing () const
 
ENGINE_API void SetCompressedPing (const uint8 NewPing)
 
ENGINE_API float GetPingInMilliseconds () const
 
bool IsSpectator () const
 
ENGINE_API void SetIsSpectator (const bool bNewSpectator)
 
bool IsOnlyASpectator () const
 
ENGINE_API void SetIsOnlyASpectator (const bool bNewSpectator)
 
bool IsABot () const
 
ENGINE_API void SetIsABot (const bool bNewIsABot)
 
bool IsInactive () const
 
ENGINE_API void SetIsInactive (const bool bNewInactive)
 
bool IsFromPreviousLevel () const
 
ENGINE_API void SetIsFromPreviousLevel (const bool bNewFromPreviousLevel)
 
int32 GetStartTime () const
 
ENGINE_API void SetStartTime (const int32 NewStartTime)
 
const FUniqueNetIdReplGetUniqueId () const
 
ENGINE_API FUniqueNetIdRepl BP_GetUniqueId () const
 
ENGINE_API void SetUniqueId (const FUniqueNetIdRepl &NewUniqueId)
 
ENGINE_API void SetUniqueId (FUniqueNetIdRepl &&NewUniqueId)
 
virtual ENGINE_API void OnSetUniqueId ()
 

Public Attributes

uint8 bHasBeenWelcomed:1
 
uint8 bUseCustomPlayerNames: 1
 
TSubclassOf< class ULocalMessageEngineMessageClass
 
float ExactPing
 
FString SavedNetworkAddress
 
FName SessionName
 
FOnPlayerStatePawnSet OnPawnSet
 

Protected Member Functions

virtual ENGINE_API void OverrideWith (APlayerState *PlayerState)
 
virtual ENGINE_API void CopyProperties (APlayerState *PlayerState)
 
ENGINE_API void ReceiveOverrideWith (APlayerState *OldPlayerState)
 
ENGINE_API void ReceiveCopyProperties (APlayerState *NewPlayerState)
 
void SetShouldUpdateReplicatedPing (bool bInShouldUpdateReplicatedPing)
 
virtual ENGINE_API void HandleWelcomeMessage ()
 

Friends

struct FSetPlayerStatePawn
 

Detailed Description

A PlayerState is created for every player on a server (or in a standalone game). PlayerStates are replicated to all clients, and contain network game relevant information about the player, such as playername, score, etc.

Member Function Documentation

◆ BP_GetUniqueId()

FUniqueNetIdRepl APlayerState::BP_GetUniqueId ( ) const

Gets the online unique id for a player. If a player is logged in this will be consistent across all clients and servers.

◆ ClientInitialize()

void APlayerState::ClientInitialize ( class AController C)
virtual

Called by Controller when its PlayerState is initially replicated.

◆ CopyProperties()

void APlayerState::CopyProperties ( APlayerState PlayerState)
protectedvirtual

Copy properties which need to be saved in inactive PlayerState

◆ Destroyed()

void APlayerState::Destroyed ( )
overridevirtual

◆ DispatchCopyProperties()

void APlayerState::DispatchCopyProperties ( APlayerState PlayerState)

◆ DispatchOverrideWith()

void APlayerState::DispatchOverrideWith ( APlayerState PlayerState)

calls OverrideWith and triggers OnOverrideWith for BP extension

◆ Duplicate()

APlayerState * APlayerState::Duplicate ( )
virtual

Create duplicate PlayerState (for saving Inactive PlayerState)

◆ GetCompressedPing()

uint8 APlayerState::GetCompressedPing ( ) const
inline

Gets the literal value of the compressed Ping value (Ping = PingInMS / 4).

◆ GetHumanReadableName()

FString APlayerState::GetHumanReadableName ( ) const
overridevirtual

◆ GetLifetimeReplicatedProps()

void APlayerState::GetLifetimeReplicatedProps ( TArray< FLifetimeProperty > &  OutLifetimeProps) const
overridevirtual

◆ GetOldPlayerName()

FString APlayerState::GetOldPlayerName ( ) const
virtual

returns previous player name

◆ GetOwningController()

class AController * APlayerState::GetOwningController ( ) const

Returns the AI or player controller that created this player state, or null for remote clients

◆ GetPawn() [1/2]

APawn * APlayerState::GetPawn ( ) const
inline

Return the pawn controlled by this Player State.

◆ GetPawn() [2/2]

template<class T >
T * APlayerState::GetPawn ( ) const
inline

Convenience helper to return a cast version of the pawn controlled by this Player State.

◆ GetPingInMilliseconds()

float APlayerState::GetPingInMilliseconds ( ) const

Returns the ping (in milliseconds)

Returns ExactPing if available (local players or when running on the server), and the replicated CompressedPing (converted back to milliseconds) otherwise.

Note that replication of CompressedPing is controlled by bShouldUpdateReplicatedPing, and if disabled then this will return 0 or a stale value on clients for player states that aren't related to local players

◆ GetPlayerController()

class APlayerController * APlayerState::GetPlayerController ( ) const

Return the player controller that created this player state, or null for remote clients

◆ GetPlayerId()

int32 APlayerState::GetPlayerId ( ) const
inline

Gets the literal value of PlayerId.

◆ GetPlayerName()

FString APlayerState::GetPlayerName ( ) const

returns current player name

◆ GetPlayerNameCustom()

FString APlayerState::GetPlayerNameCustom ( ) const
virtual

custom access to player name, called only when bUseCustomPlayerNames is set

◆ GetScore()

float APlayerState::GetScore ( ) const
inline

Gets the literal value of Score.

◆ GetStartTime()

int32 APlayerState::GetStartTime ( ) const
inline

Gets the literal value of StartTime.

◆ GetUniqueId()

const FUniqueNetIdRepl & APlayerState::GetUniqueId ( ) const
inline

Gets the literal value of UniqueId.

◆ HandleWelcomeMessage()

void APlayerState::HandleWelcomeMessage ( )
protectedvirtual

called after receiving player name

◆ IsABot()

bool APlayerState::IsABot ( ) const
inline

Gets the literal value of bIsABot.

◆ IsFromPreviousLevel()

bool APlayerState::IsFromPreviousLevel ( ) const
inline

Gets the literal value of bFromPreviousLevel.

◆ IsInactive()

bool APlayerState::IsInactive ( ) const
inline

Gets the literal value of bIsInactive.

◆ IsOnlyASpectator()

bool APlayerState::IsOnlyASpectator ( ) const
inline

Gets the literal value of bOnlySpectator.

◆ IsSpectator()

bool APlayerState::IsSpectator ( ) const
inline

Gets the literal value of bIsSpectator.

◆ OnDeactivated()

void APlayerState::OnDeactivated ( )
virtual

Called on the server when the owning player has disconnected, by default this method destroys this player state

◆ OnReactivated()

void APlayerState::OnReactivated ( )
virtual

Called on the server when the owning player has reconnected and this player state is added to the active players array

◆ OnRep_bIsInactive()

void APlayerState::OnRep_bIsInactive ( )
virtual

◆ OnRep_PlayerId()

void APlayerState::OnRep_PlayerId ( )
virtual

◆ OnRep_PlayerName()

void APlayerState::OnRep_PlayerName ( )
virtual

◆ OnRep_Score()

void APlayerState::OnRep_Score ( )
virtual

Replication Notification Callbacks

◆ OnRep_UniqueId()

void APlayerState::OnRep_UniqueId ( )
virtual

◆ OnSetUniqueId()

void APlayerState::OnSetUniqueId ( )
virtual

Called on both the client and server when unique ID has been modified

◆ OverrideWith()

void APlayerState::OverrideWith ( APlayerState PlayerState)
protectedvirtual

◆ PostInitializeComponents()

void APlayerState::PostInitializeComponents ( )
overridevirtual

◆ RecalculateAvgPing()

void APlayerState::RecalculateAvgPing ( )
virtual

Recalculates the replicated Ping value once per second (both clientside and serverside), based upon collected ping data

◆ ReceiveCopyProperties()

ENGINE_API void APlayerState::ReceiveCopyProperties ( APlayerState NewPlayerState)
protected

◆ ReceiveOverrideWith()

ENGINE_API void APlayerState::ReceiveOverrideWith ( APlayerState OldPlayerState)
protected

◆ RegisterPlayerWithSession()

void APlayerState::RegisterPlayerWithSession ( bool  bWasFromInvite)
virtual

Register a player with the online subsystem

Parameters
bWasFromInvitewas this player invited directly

◆ Reset()

void APlayerState::Reset ( )
overridevirtual

◆ SeamlessTravelTo()

void APlayerState::SeamlessTravelTo ( class APlayerState NewPlayerState)
virtual

called by seamless travel when initializing a player on the other side - copy properties to the new PlayerState that should persist

◆ SetCompressedPing()

void APlayerState::SetCompressedPing ( const uint8  NewPing)

Sets the value of CompressedPing without causing other side effects to this instance.

◆ SetIsABot()

void APlayerState::SetIsABot ( const bool  bNewIsABot)

Sets the value of bIsABot without causing other side effects to this instance.

◆ SetIsFromPreviousLevel()

void APlayerState::SetIsFromPreviousLevel ( const bool  bNewFromPreviousLevel)

Sets the value of bFromPreviousLevel without causing other side effects to this instance.

◆ SetIsInactive()

void APlayerState::SetIsInactive ( const bool  bNewInactive)

Sets the value of bIsInactive without causing other side effects to this instance.

◆ SetIsOnlyASpectator()

void APlayerState::SetIsOnlyASpectator ( const bool  bNewSpectator)

Sets the value of bOnlySpectator without causing other side effects to this instance.

◆ SetIsSpectator()

void APlayerState::SetIsSpectator ( const bool  bNewSpectator)

Sets the value of bIsSpectator without causing other side effects to this instance.

◆ SetOldPlayerName()

void APlayerState::SetOldPlayerName ( const FString &  S)
virtual

set the player name to S

◆ SetPlayerId()

void APlayerState::SetPlayerId ( const int32  NewId)

Sets the value of PlayerId without causing other side effects to this instance.

◆ SetPlayerName()

void APlayerState::SetPlayerName ( const FString &  S)
virtual

set the player name to S

◆ SetPlayerNameInternal()

void APlayerState::SetPlayerNameInternal ( const FString &  S)
virtual

set the player name to S locally, does not trigger net updates

◆ SetScore()

void APlayerState::SetScore ( const float  NewScore)

Sets the value of Score without causing other side effects to this instance.

◆ SetShouldUpdateReplicatedPing()

void APlayerState::SetShouldUpdateReplicatedPing ( bool  bInShouldUpdateReplicatedPing)
inlineprotected

Sets whether or not the replicated ping value is updated automatically.

◆ SetStartTime()

void APlayerState::SetStartTime ( const int32  NewStartTime)

Sets the value of StartTime without causing other side effects to this instance.

◆ SetUniqueId() [1/2]

void APlayerState::SetUniqueId ( const FUniqueNetIdRepl NewUniqueId)

Associate an online unique id with this player

Parameters
InUniqueIdthe unique id associated with this player

◆ SetUniqueId() [2/2]

void APlayerState::SetUniqueId ( FUniqueNetIdRepl &&  NewUniqueId)

Associate an online unique id with this player

Parameters
InUniqueIdthe unique id associated with this player

◆ ShouldBroadCastWelcomeMessage()

bool APlayerState::ShouldBroadCastWelcomeMessage ( bool  bExiting = false)
virtual

Returns true if should broadcast player welcome/left messages. Current conditions: must be a human player a network game

◆ UnregisterPlayerWithSession()

void APlayerState::UnregisterPlayerWithSession ( )
virtual

Unregister a player with the online subsystem

◆ UpdatePing()

void APlayerState::UpdatePing ( float  InPing)
virtual

Receives ping updates for the client (both clientside and serverside), from the net driver NOTE: This updates much more frequently clientside, thus the clientside ping will often be different to what the server displays

Friends And Related Symbol Documentation

◆ FSetPlayerStatePawn

Member Data Documentation

◆ bHasBeenWelcomed

uint8 APlayerState::bHasBeenWelcomed

client side flag - whether this player has been welcomed or not (player entered message)

◆ bUseCustomPlayerNames

uint8 APlayerState::bUseCustomPlayerNames

if set, GetPlayerName() will call virtual GetPlayerNameCustom() to allow custom access

◆ EngineMessageClass

TSubclassOf<class ULocalMessage> APlayerState::EngineMessageClass

This is used for sending game agnostic messages that can be localized

◆ ExactPing

float APlayerState::ExactPing

Exact ping in milliseconds as float (rounded and compressed in replicated CompressedPing)

◆ OnPawnSet

FOnPlayerStatePawnSet APlayerState::OnPawnSet

Broadcast whenever this player's possessed pawn is set

◆ SavedNetworkAddress

FString APlayerState::SavedNetworkAddress

Used to match up InactivePlayerState with rejoining playercontroller.

◆ SessionName

FName APlayerState::SessionName

The session that the player needs to join/remove from as it is created/leaves


The documentation for this class was generated from the following files: