APlayerState::ClientInitialize
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: virtual
Description
Called by the owning Controller on the client (or server in standalone) when the PlayerState is initially replicated and the controller links to it. Use this for client-side initialization that depends on both the controller and the player state being ready.
Caveats & Gotchas
- • This is called once per PlayerState lifetime when the controller first receives its replicated PlayerState. It is not called again on subsequent state updates — for ongoing replication use the OnRep_* callbacks.
- • Always call Super::ClientInitialize(C). The base implementation broadcasts the pawn-set delegate if a pawn is already associated, ensuring listeners bound before possession are notified correctly.
- • C may be an AIController in singleplayer or listen-server scenarios. Always check Cast<APlayerController>(C) before accessing player-controller-specific members.
Signature
ENGINE_API virtual void ClientInitialize(class AController* C); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| C | class AController* | The controller that owns this PlayerState and has just received its initial replication. | — |
Return Type
void Example
Apply locally stored control preferences when player state is linked C++
void AMyPlayerState::ClientInitialize(AController* C)
{
Super::ClientInitialize(C); // Required — notifies pawn-set delegate
if (APlayerController* PC = Cast<APlayerController>(C))
{
PC->SetMouseSensitivity(GetStoredSensitivity());
}
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?