AGameModeBase::SetPlayerDefaults
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Called from RestartPlayer after a pawn has been spawned and possessed to apply any game-mode-specific default stats or equipment. Override this to initialize health, load inventory, or set starting attributes.
Caveats & Gotchas
- • The default implementation is empty — if you don't override this, no defaults are applied beyond what the pawn's own constructor sets.
- • Called after possession, so the pawn's controller is valid inside this function. However, it fires before K2_OnRestartPlayer — put logic that depends on other post-spawn systems in the Blueprint event instead.
- • Not called when a pawn is spawned outside the normal RestartPlayer flow (e.g., direct SpawnActor calls). If you use custom spawn paths, call SetPlayerDefaults manually or duplicate the initialization logic.
Signature
ENGINE_API virtual void SetPlayerDefaults(APawn* PlayerPawn); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| PlayerPawn | APawn* | The newly spawned pawn to initialize. | — |
Return Type
void Example
Apply starting health and loadout C++
void AMyGameMode::SetPlayerDefaults(APawn* PlayerPawn)
{
Super::SetPlayerDefaults(PlayerPawn);
if (AMyCharacter* Char = Cast<AMyCharacter>(PlayerPawn))
{
Char->SetHealth(Char->GetMaxHealth());
Char->EquipDefaultWeapon();
}
} Tags
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?