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