RealDocs

APlayerState::OnPawnSet

property Engine Blueprint Since 4.14
#include "GameFramework/PlayerState.h"
Access: public Specifiers: UPROPERTYBlueprintAssignable

Description

Multicast delegate broadcast whenever the pawn associated with this PlayerState changes. Fires with the PlayerState, the new pawn, and the old pawn — useful for syncing per-player data to a newly possessed pawn.

Caveats & Gotchas

  • The delegate fires on both possession and un-possession. When a pawn is unpossessed, NewPawn will be null and OldPawn will be the pawn that was just disassociated. Always null-check NewPawn before using it.
  • This fires after SetPawnPrivate has already updated the internal pointer, so calling GetPawn() inside the bound function will return the new pawn (NewPawn), matching the delegate argument.
  • The delegate is declared with DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE. Bindings are not replicated — each machine must bind independently, and the delegate only fires locally on whichever machine processes the pawn-set call.

Signature

FOnPlayerStatePawnSet OnPawnSet

Example

Sync player cosmetics to a newly possessed pawn C++
void AMyGameMode::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);
	if (AMyPlayerState* PS = NewPlayer->GetPlayerState<AMyPlayerState>())
	{
		PS->OnPawnSet.AddDynamic(this, &AMyGameMode::OnPlayerPawnSet);
	}
}

void AMyGameMode::OnPlayerPawnSet(APlayerState* Player, APawn* NewPawn, APawn* OldPawn)
{
	if (NewPawn)
	{
		if (auto* MyChar = Cast<AMyCharacter>(NewPawn))
		{
			if (auto* MyPS = Cast<AMyPlayerState>(Player))
			{
				MyChar->ApplyCosmetics(MyPS);
			}
		}
	}
}

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.