UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PlayerState.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "Online/CoreOnline.h"
11#include "GameFramework/Info.h"
12#include "PlayerState.generated.h"
13
19{
22
25
28 : PingSum(0)
29 , PingCount(0)
30 {
31 }
32};
33
35
40UCLASS(BlueprintType, Blueprintable, notplaceable, MinimalAPI)
41class APlayerState : public AInfo
42{
44
45private:
46
48 UPROPERTY(ReplicatedUsing = OnRep_Score, Category = PlayerState, BlueprintGetter = GetScore)
49 float Score;
50
52 UPROPERTY(ReplicatedUsing = OnRep_PlayerId, Category = PlayerState, BlueprintGetter = GetPlayerId)
53 int32 PlayerId;
54
56 UPROPERTY(Replicated, Category=PlayerState, BlueprintGetter=GetCompressedPing, meta=(AllowPrivateAccess))
57 uint8 CompressedPing;
58
60 uint8 CurPingBucket;
61
68 UPROPERTY(EditDefaultsOnly, Category=PlayerState)
69 uint8 bShouldUpdateReplicatedPing:1;
70
72 UPROPERTY(Replicated, Category=PlayerState, BlueprintGetter=IsSpectator)
73 uint8 bIsSpectator:1;
74
77 uint8 bOnlySpectator:1;
78
80 UPROPERTY(Replicated, Category=PlayerState, BlueprintGetter=IsABot)
81 uint8 bIsABot:1;
82
83public:
86
87private:
88
90 UPROPERTY(ReplicatedUsing=OnRep_bIsInactive)
91 uint8 bIsInactive:1;
92
98 uint8 bFromPreviousLevel:1;
99
100public:
101
104
105private:
106
109 int32 StartTime;
110
115 UPROPERTY(ReplicatedUsing = OnRep_UniqueId)
116 FUniqueNetIdRepl UniqueId;
117
118public:
120 UPROPERTY()
121 TSubclassOf<class ULocalMessage> EngineMessageClass;
122
124 float ExactPing;
125
127 UPROPERTY()
128 FString SavedNetworkAddress;
129
131 FName SessionName;
132
134 UPROPERTY(BlueprintAssignable, Category = "Events")
136
137private:
138
140
142 UPROPERTY(BlueprintReadOnly, Category=PlayerState, meta=(AllowPrivateAccess="true"))
143 TObjectPtr<APawn> PawnPrivate;
144
145 ENGINE_API void SetPawnPrivate(APawn* InPawn);
146
147 UFUNCTION()
148 ENGINE_API void OnPawnPrivateDestroyed(AActor* InActor);
149
155 PingAvgData PingBucket[4];
156
158 float CurPingBucketTimestamp;
159
161 UPROPERTY(ReplicatedUsing = OnRep_PlayerName)
162 FString PlayerNamePrivate;
163
165 FString OldNamePrivate;
166
167public:
169 UFUNCTION()
170 ENGINE_API virtual void OnRep_Score();
171
172 UFUNCTION()
173 ENGINE_API virtual void OnRep_PlayerName();
174
175 UFUNCTION()
176 ENGINE_API virtual void OnRep_bIsInactive();
177
178 UFUNCTION()
179 ENGINE_API virtual void OnRep_PlayerId();
180
181 UFUNCTION()
182 ENGINE_API virtual void OnRep_UniqueId();
183
184 //~ Begin AActor Interface
185 ENGINE_API virtual void PostInitializeComponents() override;
188 ENGINE_API virtual FString GetHumanReadableName() const override;
189 //~ End AActor Interface
190
192 UFUNCTION(BlueprintCallable, Category = "PlayerState")
193 APawn* GetPawn() const { return PawnPrivate; }
194
196 template<class T>
197 T* GetPawn() const { return Cast<T>(PawnPrivate); }
198
200 ENGINE_API class AController* GetOwningController() const;
201
203 UFUNCTION(BlueprintCallable, Category = "PlayerState")
204 ENGINE_API class APlayerController* GetPlayerController() const;
205
207 ENGINE_API virtual void ClientInitialize(class AController* C);
208
213 ENGINE_API virtual void UpdatePing(float InPing);
214
216 ENGINE_API virtual void RecalculateAvgPing();
217
222 ENGINE_API virtual bool ShouldBroadCastWelcomeMessage(bool bExiting = false);
223
225 ENGINE_API virtual void SetPlayerName(const FString& S);
226
228 ENGINE_API virtual void SetPlayerNameInternal(const FString& S);
229
231 UFUNCTION(BlueprintPure, Category = PlayerState)
232 ENGINE_API FString GetPlayerName() const;
233
235 ENGINE_API virtual FString GetPlayerNameCustom() const;
236
238 ENGINE_API virtual FString GetOldPlayerName() const;
239
241 ENGINE_API virtual void SetOldPlayerName(const FString& S);
242
247 ENGINE_API virtual void RegisterPlayerWithSession(bool bWasFromInvite);
248
250 ENGINE_API virtual void UnregisterPlayerWithSession();
251
254
256 ENGINE_API virtual void OnDeactivated();
257
259 ENGINE_API virtual void OnReactivated();
260
262 ENGINE_API virtual void SeamlessTravelTo(class APlayerState* NewPlayerState);
263
265
267 ENGINE_API void DispatchOverrideWith(APlayerState* PlayerState);
268
269 ENGINE_API void DispatchCopyProperties(APlayerState* PlayerState);
270
272
273 ENGINE_API virtual void OverrideWith(APlayerState* PlayerState);
274
276 ENGINE_API virtual void CopyProperties(APlayerState* PlayerState);
277
278 /*
279 * Can be implemented in Blueprint Child to move more properties from old to new PlayerState when reconnecting
280 *
281 * @param OldPlayerState Old PlayerState, which we use to fill the new one with
282 */
283 UFUNCTION(BlueprintImplementableEvent, Category = PlayerState, meta = (DisplayName = "OverrideWith"))
284 ENGINE_API void ReceiveOverrideWith(APlayerState* OldPlayerState);
285
286 /*
287 * Can be implemented in Blueprint Child to move more properties from old to new PlayerState when traveling to a new level
288 *
289 * @param NewPlayerState New PlayerState, which we fill with the current properties
290 */
291 UFUNCTION(BlueprintImplementableEvent, Category = PlayerState, meta = (DisplayName = "CopyProperties"))
292 ENGINE_API void ReceiveCopyProperties(APlayerState* NewPlayerState);
293
295 void SetShouldUpdateReplicatedPing(bool bInShouldUpdateReplicatedPing) { bShouldUpdateReplicatedPing = bInShouldUpdateReplicatedPing; }
296
298 ENGINE_API virtual void HandleWelcomeMessage();
299
300private:
301 // Hidden functions that don't make sense to use on this class.
303
304 //~ Begin Methods for Replicated Members.
305public:
306
308 UFUNCTION(BlueprintGetter)
309 float GetScore() const
310 {
311 return Score;
312 }
313
315 ENGINE_API void SetScore(const float NewScore);
316
318 UFUNCTION(BlueprintGetter)
319 int32 GetPlayerId() const
320 {
321 return PlayerId;
322 }
323
325 ENGINE_API void SetPlayerId(const int32 NewId);
326
328 UFUNCTION(BlueprintGetter)
329 uint8 GetCompressedPing() const
330 {
331 return CompressedPing;
332 }
333
335 ENGINE_API void SetCompressedPing(const uint8 NewPing);
336
347 UFUNCTION(BlueprintCallable, Category = "PlayerState")
348 ENGINE_API float GetPingInMilliseconds() const;
349
351 UFUNCTION(BlueprintGetter)
352 bool IsSpectator() const
353 {
354 return bIsSpectator;
355 }
356
358 ENGINE_API void SetIsSpectator(const bool bNewSpectator);
359
361 UFUNCTION(BlueprintCallable, Category = "PlayerState")
362 bool IsOnlyASpectator() const
363 {
364 return bOnlySpectator;
365 }
366
368 ENGINE_API void SetIsOnlyASpectator(const bool bNewSpectator);
369
371 UFUNCTION(BlueprintGetter)
372 bool IsABot() const
373 {
374 return bIsABot;
375 }
376
378 ENGINE_API void SetIsABot(const bool bNewIsABot);
379
381 bool IsInactive() const
382 {
383 return bIsInactive;
384 }
385
387 ENGINE_API void SetIsInactive(const bool bNewInactive);
388
391 {
392 return bFromPreviousLevel;
393 }
394
396 ENGINE_API void SetIsFromPreviousLevel(const bool bNewFromPreviousLevel);
397
400 {
401 return StartTime;
402 }
403
405 ENGINE_API void SetStartTime(const int32 NewStartTime);
406
409 {
410 return UniqueId;
411 }
412
414 UFUNCTION(BlueprintCallable, Category = "PlayerState", meta = (DisplayName = "Get Unique Net Id"))
415 ENGINE_API FUniqueNetIdRepl BP_GetUniqueId() const;
416
421 ENGINE_API void SetUniqueId(const FUniqueNetIdRepl& NewUniqueId);
422
427 ENGINE_API void SetUniqueId(FUniqueNetIdRepl&& NewUniqueId);
428
430 ENGINE_API virtual void OnSetUniqueId();
431
432 //~ End Methods for Replicated Members.
433};
434
436{
437private:
438
439 friend APawn;
440
442 {
443 APawn* OldPawn = PlayerState->PawnPrivate;
444 PlayerState->SetPawnPrivate(Pawn);
445 PlayerState->OnPawnSet.Broadcast(PlayerState, PlayerState->PawnPrivate, OldPawn);
446 }
447};
#define HIDE_ACTOR_TRANSFORM_FUNCTIONS()
Definition Actor.h:5033
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(DelegateName, Param1Type, Param1Name, Param2Type, Param2Name, Param3Type, Param3Name)
Definition DelegateCombinations.h:71
return true
Definition ExternalRpcRegistry.cpp:601
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
Definition Actor.h:257
FName Tag const
Definition Actor.h:3810
Definition Controller.h:41
virtual ENGINE_API void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > &OutLifetimeProps) const override
Definition Controller.cpp:797
TObjectPtr< APlayerState > PlayerState
Definition Controller.h:50
Definition PlayerController.h:261
Definition PlayerState.h:42
bool IsFromPreviousLevel() const
Definition PlayerState.h:390
FOnPlayerStatePawnSet OnPawnSet
Definition PlayerState.h:135
T * GetPawn() const
Definition PlayerState.h:197
uint8 bHasBeenWelcomed
Definition PlayerState.h:85
bool IsInactive() const
Definition PlayerState.h:381
const FUniqueNetIdRepl & GetUniqueId() const
Definition PlayerState.h:408
int32 GetStartTime() const
Definition PlayerState.h:399
uint8 bUseCustomPlayerNames
Definition PlayerState.h:103
Definition CoreNet.h:300
Definition NameTypes.h:617
Definition Array.h:670
Definition SubclassOf.h:30
Definition LocalMessage.h:58
@ false
Definition radaudio_common.h:23
Definition PlayerState.h:436
Definition OnlineReplStructs.h:26
Definition PlayerState.h:19
PingAvgData()
Definition PlayerState.h:27
uint8 PingCount
Definition PlayerState.h:24
uint16 PingSum
Definition PlayerState.h:21
Definition ObjectPtr.h:488