APlayerState

A PlayerState is created for every player on a server (or in a standalone game).

Inheritance Hierarchy

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/GameFramework/PlayerState.h

Include

#include "GameFramework/PlayerState.h"

Syntax

class APlayerState : public AInfo

Remarks

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.

Variables

Name Description

Public variable

uint8: 1

 

bHasBeenWelcomed

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

Public variable

uint8: 1

 

bUseCustomPlayerNames

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

Public variable

TSubclassOf< cl...

 

EngineMessageClass

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

Public variable

float

 

ExactPing

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

Public variable

FOnPlayerStateP...

 

OnPawnSet

Broadcast whenever this player's possessed pawn is set

Public variable

FString

 

SavedNetworkAddress

Used to match up InactivePlayerState with rejoining playercontroller.

Public variable

FName

 

SessionName

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

Constructors

Name Description

Public function

APlayerState

(
    const FObjectInitializer& ObjectIn...
)

Destructors

Name Description

Public function Virtual

~APlayerState()

Destructor for handling property deprecation, please remove after all deprecated properties are gone

Functions

Name Description

Public function Const

FUniqueNetId...

 

BP_GetUniqueId()

Gets the online unique id for a player.

Public function Virtual

void

 

ClientInitialize

(
    AController* C
)

Called by Controller when its PlayerState is initially replicated.

Protected function Virtual

void

 

CopyProperties

(
    APlayerState* PlayerState
)

Copy properties which need to be saved in inactive PlayerState

Public function

void

 

DispatchCopyProperties

(
    APlayerState* PlayerState
)

Public function

void

 

DispatchOverrideWith

(
    APlayerState* PlayerState
)

Calls OverrideWith and triggers OnOverrideWith for BP extension

Public function Virtual

APlayerState...

 

Duplicate()

Create duplicate PlayerState (for saving Inactive PlayerState)

Public function Const

uint8

 

GetCompressedPing()

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

Public function Virtual Const

FString

 

GetOldPlayerName()

Returns previous player name

Public function Const

AController ...

 

GetOwningController()

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

Public function Const

T *

 

GetPawn()

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

Public function Const

APawn *

 

GetPawn()

Return the pawn controlled by this Player State.

Public function Const

float

 

GetPingInMilliseconds()

Returns the ping (in milliseconds)

Public function Const

APlayerContr...

 

GetPlayerController()

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

Public function Const

int32

 

GetPlayerId()

Gets the literal value of PlayerId.

Public function Const

FString

 

GetPlayerName()

Returns current player name

Public function Virtual Const

FString

 

GetPlayerNameCustom()

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

Public function Const

float

 

GetScore()

Gets the literal value of Score.

Public function Const

int32

 

GetStartTime()

Gets the literal value of StartTime.

Public function Const

const FUniqu...

 

GetUniqueId()

Gets the literal value of UniqueId.

Protected function Virtual

void

 

HandleWelcomeMessage()

Called after receiving player name

Public function Const

bool

 

IsABot()

Gets the literal value of bIsABot.

Public function Const

bool

 

IsFromPreviousLevel()

Gets the literal value of bFromPreviousLevel.

Public function Const

bool

 

IsInactive()

Gets the literal value of bIsInactive.

Public function Const

bool

 

IsOnlyASpectator()

Gets the literal value of bOnlySpectator.

Public function Const

bool

 

IsSpectator()

Gets the literal value of bIsSpectator.

Public function Virtual

void

 

OnDeactivated()

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

Public function Virtual

void

 

OnReactivated()

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

Public function Virtual

void

 

OnRep_bIsInactive()

Public function Virtual

void

 

OnRep_PlayerId()

Public function Virtual

void

 

OnRep_PlayerName()

Public function Virtual

void

 

OnRep_Score()

Replication Notification Callbacks

Public function Virtual

void

 

OnRep_UniqueId()

Public function Virtual

void

 

OnSetUniqueId()

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

Protected function Virtual

void

 

OverrideWith

(
    APlayerState* PlayerState
)

Public function Virtual

void

 

RecalculateAvgPing()

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

Protected function

void

 

ReceiveCopyProperties

(
    APlayerState* NewPlayerState
)

Can be implemented in Blueprint Child to move more properties from old to new PlayerState when traveling to a new level

Protected function

void

 

ReceiveOverrideWith

(
    APlayerState* OldPlayerState
)

Can be implemented in Blueprint Child to move more properties from old to new PlayerState when reconnecting

Public function Virtual

void

 

RegisterPlayerWithSession

(
    bool bWasFromInvite
)

Register a player with the online subsystem

Public function Virtual

void

 

SeamlessTravelTo

(
    APlayerState* NewPlayerState
)

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

Public function

void

 

SetCompressedPing

(
    const uint8 NewPing
)

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

Public function

void

 

SetIsABot

(
    const bool bNewIsABot
)

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

Public function

void

 

SetIsFromPreviousLevel

(
    const bool bNewFromPreviousLevel
)

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

Public function

void

 

SetIsInactive

(
    const bool bNewInactive
)

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

Public function

void

 

SetIsOnlyASpectator

(
    const bool bNewSpectator
)

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

Public function

void

 

SetIsSpectator

(
    const bool bNewSpectator
)

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

Public function Virtual

void

 

SetOldPlayerName

(
    const FString& S
)

Set the player name to S

Public function

void

 

SetPlayerId

(
    const int32 NewId
)

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

Public function Virtual

void

 

SetPlayerName

(
    const FString& S
)

Set the player name to S

Public function Virtual

void

 

SetPlayerNameInternal

(
    const FString& S
)

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

Public function

void

 

SetScore

(
    const float NewScore
)

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

Protected function

void

 

SetShouldUpdateReplicatedPing

(
    bool bInShouldUpdateReplicatedPing
)

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

Public function

void

 

SetStartTime

(
    const int32 NewStartTime
)

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

Public function

void

 

SetUniqueId

(
    const FUniqueNetIdRepl& NewUniqueI...
)

Associate an online unique id with this player

Public function

void

 

SetUniqueId

(
    FUniqueNetIdRepl&& NewUniqueId
)

Associate an online unique id with this player

Public function Virtual

bool

 

ShouldBroadCastWelcomeMessage

(
    bool bExiting
)

Returns true if should broadcast player welcome/left messages.

Public function Virtual

void

 

UnregisterPlayerWithSession()

Unregister a player with the online subsystem

Public function Virtual

void

 

UpdatePing

(
    float InPing
)

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

Overridden from AActor

Name Description

Public function Virtual

void

 

Destroyed()

Called when this actor is explicitly being destroyed during gameplay or in the editor, not called during level streaming or gameplay ending

Public function Virtual Const

FString

 

GetHumanReadableName()

Returns the human readable string representation of an object.

Public function Virtual

void

 

PostInitializeComponents()

Allow actors to initialize themselves on the C++ side after all of their components have been initialized, only called during gameplay

Public function Virtual

void

 

Reset()

Reset actor to initial state - used when restarting level without reloading.

Overridden from UObject

Name Description

Public function Virtual Const

void

 

GetLifetimeReplicatedProps

(
    TArray< FLifetimeProperty >& OutLi...
)

Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties

Deprecated Variables

Name Description

Public variable

uint8: 1

 

bFromPreviousLevel

This member will be made private. Use IsFromPreviousLevel or SetIsFromPreviousLevel instead.

Public variable

uint8: 1

 

bIsABot

This member will be made private. Use IsABot or SetIsABot instead.

Public variable

uint8: 1

 

bIsInactive

This member will be made private. Use IsInactive or SetIsInactive instead.

Public variable

uint8: 1

 

bIsSpectator

This member will be made private. Use IsSpectator or SetIsSpectator instead.

Public variable

uint8: 1

 

bOnlySpectator

This member will be made private. Use IsOnlyASpectator or SetIsOnlyASpectator instead.

Public variable

int32

 

PlayerId

This member will be made private. Use GetPlayerId or SetPlayerId instead.

Public variable

float

 

Score

This member will be made private. Use GetScore or SetScore instead.

Public variable

int32

 

StartTime

This member will be made private. Use GetStartTime or SetStartTime instead.

Public variable

FUniqueNetIdRep...

 

UniqueId

This member will be made private. Use GetUniqueId or SetUniqueId instead.

Deprecated Functions

Name Description

Public function Virtual Const

bool

 

IsPrimaryPlayer()

This version of IsPrimaryPlayer has been deprecated, please use the Platform Device Mapper to check the owning PlatformUserId instead.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Cancel