Navigation
API > API/Runtime > API/Runtime/Engine
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.
| Name | APlayerState |
| Type | class |
| Header File | /Engine/Source/Runtime/Engine/Classes/GameFramework/PlayerState.h |
| Include Path | #include "GameFramework/PlayerState.h" |
Syntax
UCLASS (BlueprintType, Blueprintable, NotPlaceable, MinimalAPI)
class APlayerState : public AInfo
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → AActor → AInfo → APlayerState
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
APlayerState
(
const FObjectInitializer& ObjectInitializer |
GameFramework/PlayerState.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bHasBeenWelcomed | uint8 | Client side flag - whether this player has been welcomed or not (player entered message) | GameFramework/PlayerState.h | |
| bUseCustomPlayerNames | uint8 | If set, GetPlayerName() will call virtual GetPlayerNameCustom() to allow custom access | GameFramework/PlayerState.h | |
| EngineMessageClass | TSubclassOf< class ULocalMessage > | This is used for sending game agnostic messages that can be localized | GameFramework/PlayerState.h | |
| ExactPing | float | Exact ping in milliseconds as float (rounded and compressed in replicated CompressedPing) | GameFramework/PlayerState.h | |
| OnPawnSet | FOnPlayerStatePawnSet | Broadcast whenever this player's possessed pawn is set | GameFramework/PlayerState.h |
|
| SavedNetworkAddress | FString | Used to match up InactivePlayerState with rejoining playercontroller. | GameFramework/PlayerState.h | |
| SessionName | FName | The session that the player needs to join/remove from as it is created/leaves | GameFramework/PlayerState.h |
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bFromPreviousLevel | uint8 | 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 | GameFramework/PlayerState.h |
|
| bIsABot | uint8 | True if this PlayerState is associated with an AIController | GameFramework/PlayerState.h |
|
| bIsInactive | uint8 | Means this PlayerState came from the GameMode's InactivePlayerArray | GameFramework/PlayerState.h |
|
| bIsSpectator | uint8 | Whether this player is currently a spectator | GameFramework/PlayerState.h |
|
| bOnlySpectator | uint8 | Whether this player can only ever be a spectator | GameFramework/PlayerState.h |
|
| bShouldUpdateReplicatedPing | uint8 | Whether or not this player's replicated CompressedPing value is updated automatically. | GameFramework/PlayerState.h |
|
| CompressedPing | uint8 | Replicated compressed ping for this player (holds ping in msec divided by 4) | GameFramework/PlayerState.h |
|
| CurPingBucket | uint8 | The current PingBucket index that is being filled | GameFramework/PlayerState.h | |
| CurPingBucketTimestamp | float | The timestamp for when the current PingBucket began filling | GameFramework/PlayerState.h | |
| OldNamePrivate | FString | Previous player name. Saved on client-side to detect player name changes. | GameFramework/PlayerState.h | |
| PawnPrivate | TObjectPtr< APawn > | The pawn that is controlled by by this player state. | GameFramework/PlayerState.h |
|
| PingBucket | PingAvgData | Stores the last 4 seconds worth of ping data (one second per 'bucket'). | GameFramework/PlayerState.h | |
| PlayerId | int32 | Unique net id number. | GameFramework/PlayerState.h |
|
| PlayerNamePrivate | FString | Player name, or blank if none. | GameFramework/PlayerState.h |
|
| Score | float | Player's current score. | GameFramework/PlayerState.h |
|
| StartTime | int32 | Elapsed time on server when this PlayerState was first created. | GameFramework/PlayerState.h |
|
| UniqueId | FUniqueNetIdRepl | The id used by the network to uniquely identify a player. | GameFramework/PlayerState.h |
|
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Gets the online unique id for a player. | GameFramework/PlayerState.h |
|
|
virtual void ClientInitialize
(
AController* C |
Called by Controller when its PlayerState is initially replicated. | GameFramework/PlayerState.h | |
void DispatchCopyProperties
(
APlayerState* PlayerState |
GameFramework/PlayerState.h | ||
void DispatchOverrideWith
(
APlayerState* PlayerState |
Calls OverrideWith and triggers OnOverrideWith for BP extension | GameFramework/PlayerState.h | |
virtual APlayerState * Duplicate() |
Create duplicate PlayerState (for saving Inactive PlayerState) | GameFramework/PlayerState.h | |
uint8 GetCompressedPing() |
Gets the literal value of the compressed Ping value (Ping = PingInMS / 4). | GameFramework/PlayerState.h |
|
virtual FString GetOldPlayerName() |
Returns previous player name | GameFramework/PlayerState.h | |
AController * GetOwningController() |
Returns the AI or player controller that created this player state, or null for remote clients | GameFramework/PlayerState.h | |
T * GetPawn () |
Convenience helper to return a cast version of the pawn controlled by this Player State. | GameFramework/PlayerState.h | |
| Return the pawn controlled by this Player State. | GameFramework/PlayerState.h |
|
|
float GetPingInMilliseconds () |
Returns the ping (in milliseconds) | GameFramework/PlayerState.h |
|
APlayerController * GetPlayerController() |
Return the player controller that created this player state, or null for remote clients | GameFramework/PlayerState.h |
|
int32 GetPlayerId() |
Gets the literal value of PlayerId. | GameFramework/PlayerState.h |
|
FString GetPlayerName() |
Returns current player name | GameFramework/PlayerState.h |
|
virtual FString GetPlayerNameCustom() |
Custom access to player name, called only when bUseCustomPlayerNames is set | GameFramework/PlayerState.h | |
float GetScore() |
Gets the literal value of Score. | GameFramework/PlayerState.h |
|
int32 GetStartTime() |
Gets the literal value of StartTime. | GameFramework/PlayerState.h | |
const FUniqueNetIdRepl & GetUniqueId() |
Gets the literal value of UniqueId. | GameFramework/PlayerState.h | |
bool IsABot() |
Gets the literal value of bIsABot. | GameFramework/PlayerState.h |
|
bool IsFromPreviousLevel() |
Gets the literal value of bFromPreviousLevel. | GameFramework/PlayerState.h | |
bool IsInactive() |
Gets the literal value of bIsInactive. | GameFramework/PlayerState.h | |
bool IsOnlyASpectator() |
Gets the literal value of bOnlySpectator. | GameFramework/PlayerState.h |
|
bool IsSpectator() |
Gets the literal value of bIsSpectator. | GameFramework/PlayerState.h |
|
virtual void OnDeactivated() |
Called on the server when the owning player has disconnected, by default this method destroys this player state | GameFramework/PlayerState.h | |
virtual void OnReactivated() |
Called on the server when the owning player has reconnected and this player state is added to the active players array | GameFramework/PlayerState.h | |
virtual void OnRep_bIsInactive() |
GameFramework/PlayerState.h | ||
virtual void OnRep_PlayerId() |
GameFramework/PlayerState.h | ||
virtual void OnRep_PlayerName() |
GameFramework/PlayerState.h | ||
virtual void OnRep_Score() |
Replication Notification Callbacks | GameFramework/PlayerState.h | |
virtual void OnRep_UniqueId() |
GameFramework/PlayerState.h | ||
virtual void OnSetUniqueId() |
Called on both the client and server when unique ID has been modified | GameFramework/PlayerState.h | |
virtual void RecalculateAvgPing() |
Recalculates the replicated Ping value once per second (both clientside and serverside), based upon collected ping data | GameFramework/PlayerState.h | |
virtual void RegisterPlayerWithSession
(
bool bWasFromInvite |
Register a player with the online subsystem | GameFramework/PlayerState.h | |
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 | GameFramework/PlayerState.h | |
void SetCompressedPing
(
const uint8 NewPing |
Sets the value of CompressedPing without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetIsABot
(
const bool bNewIsABot |
Sets the value of bIsABot without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetIsFromPreviousLevel
(
const bool bNewFromPreviousLevel |
Sets the value of bFromPreviousLevel without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetIsInactive
(
const bool bNewInactive |
Sets the value of bIsInactive without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetIsOnlyASpectator
(
const bool bNewSpectator |
Sets the value of bOnlySpectator without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetIsSpectator
(
const bool bNewSpectator |
Sets the value of bIsSpectator without causing other side effects to this instance. | GameFramework/PlayerState.h | |
virtual void SetOldPlayerName
(
const FString& S |
Set the player name to S | GameFramework/PlayerState.h | |
void SetPlayerId
(
const int32 NewId |
Sets the value of PlayerId without causing other side effects to this instance. | GameFramework/PlayerState.h | |
virtual void SetPlayerName
(
const FString& S |
Set the player name to S | GameFramework/PlayerState.h | |
virtual void SetPlayerNameInternal
(
const FString& S |
Set the player name to S locally, does not trigger net updates | GameFramework/PlayerState.h | |
void SetScore
(
const float NewScore |
Sets the value of Score without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetStartTime
(
const int32 NewStartTime |
Sets the value of StartTime without causing other side effects to this instance. | GameFramework/PlayerState.h | |
void SetUniqueId
(
const FUniqueNetIdRepl& NewUniqueId |
Associate an online unique id with this player | GameFramework/PlayerState.h | |
void SetUniqueId
(
FUniqueNetIdRepl&& NewUniqueId |
Associate an online unique id with this player | GameFramework/PlayerState.h | |
virtual bool ShouldBroadCastWelcomeMessage
(
bool bExiting |
Returns true if should broadcast player welcome/left messages. | GameFramework/PlayerState.h | |
virtual void UnregisterPlayerWithSession() |
Unregister a player with the online subsystem | GameFramework/PlayerState.h | |
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 | GameFramework/PlayerState.h |
Overridden from AActor
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
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 | GameFramework/PlayerState.h | |
virtual FString GetHumanReadableName() |
Returns the human readable string representation of an object. | GameFramework/PlayerState.h | |
virtual void PostInitializeComponents() |
Allow actors to initialize themselves on the C++ side after all of their components have been initialized, only called during gameplay | GameFramework/PlayerState.h | |
virtual void Reset() |
Reset actor to initial state - used when restarting level without reloading. | GameFramework/PlayerState.h |
Overridden from UObject
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void GetLifetimeReplicatedProps
(
TArray< FLifetimeProperty >& OutLifetimeProps |
Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties | GameFramework/PlayerState.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void CopyProperties
(
APlayerState* PlayerState |
Copy properties which need to be saved in inactive PlayerState | GameFramework/PlayerState.h | |
virtual void HandleWelcomeMessage() |
Called after receiving player name | GameFramework/PlayerState.h | |
virtual void OverrideWith
(
APlayerState* PlayerState |
GameFramework/PlayerState.h | ||
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 | GameFramework/PlayerState.h |
|
void ReceiveOverrideWith
(
APlayerState* OldPlayerState |
Can be implemented in Blueprint Child to move more properties from old to new PlayerState when reconnecting | GameFramework/PlayerState.h |
|
void SetShouldUpdateReplicatedPing
(
bool bInShouldUpdateReplicatedPing |
Sets whether or not the replicated ping value is updated automatically. | GameFramework/PlayerState.h |