APlayerState

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

Windows
MacOS
Linux

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 as float (rounded and compressed in replicated Ping)

Public variable

float

 

ExactPingV2

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 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 Virtual Const

FString

 

GetOldPlayerName()

Returns previous player name

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

uint8

 

GetPing()

Gets the literal value of Ping.

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 Virtual Const

bool

 

IsPrimaryPlayer()

Return true if PlayerState is primary (ie. non-splitscreen) player

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()

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

 

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

 

SetPing

(
    const uint8 NewPing
)

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

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...
)

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

Public function Virtual

void

 

SetUniqueId

(
    const TSharedPtr < const FUniqueNetI ...
)

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 IsInative 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

uint8

 

Ping

This member will be made private. Use GetPing or SetPing 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.

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback