APlayerState

Inheritance Hierarchy

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

uint32 : 1

 

bFromPreviousLevel

Indicates this is a PlayerState from the previous level of a seamless travel, waiting for the player to finish the transition before creating a new one this is used to avoid preserving the PlayerState in the InactivePlayerArray if the player leaves

Public variable

uint32 : 1

 

bHasBeenWelcomed

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

Public variable

uint32 : 1

 

bIsABot

True if this PlayerState is associated with an AIController

Public variable

uint32 : 1

 

bIsInactive

Means this PlayerState came from the GameMode's InactivePlayerArray

Public variable

uint32 : 1

 

bIsSpectator

Whether this player is currently a spectator

Public variable

uint32 : 1

 

bOnlySpectator

Whether this player can only ever be a spectator

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

FString

 

OldName

Previous player name. Saved on client-side to detect player name changes.

Public variable

uint8

 

Ping

Replicated compressed ping for this player (holds ping in msec divided by 4)

Public variable

int32

 

PlayerId

Unique net id number.

Public variable

FString

 

PlayerName

Player name, or blank if none.

Public variable

FString

 

SavedNetworkAddress

Used to match up InactivePlayerState with rejoining playercontroller.

Public variable

float

 

Score

Player's current score.

Public variable

FName

 

SessionName

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

Public variable

int32

 

StartTime

Elapsed time on server when this PlayerState was first created.

Public variable

FUniqueNetIdRep ...

 

UniqueId

The id used by the network to uniquely identify a player.

Constructors

Name Description

Public function

APlayerState

(
    const FObjectInitializer & ObjectIn...
)

============================================================================= PlayerState.cpp:

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

bool

 

IsPrimaryPlayer()

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

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

void

 

SetPlayerName

(
    const FString & S
)

Set the player name to S

Public function Virtual

void

 

SetUniqueId

(
    const TSharedPtr < const FUniqueNetI ...
)

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 once this actor has been deleted

Public function Virtual

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.

Public function Virtual

void

 

Reset()

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

References

Module

Engine

Header

Runtime/Engine/Classes/GameFramework/PlayerState.h