RealDocs

APlayerState::Duplicate

function Engine Since 4.0
#include "GameFramework/PlayerState.h"
Access: public Specifiers: virtualENGINE_API

Description

Creates a copy of this PlayerState for storage in the GameMode's InactivePlayerArray when a player disconnects. The duplicate preserves relevant state so it can be restored if the player reconnects.

Caveats & Gotchas

  • The default implementation spawns a new APlayerState via SpawnInfo and calls CopyProperties — if your subclass adds replicated properties you want persisted across reconnects, override CopyProperties rather than Duplicate.
  • The returned actor is added to InactivePlayerArray and is not assigned to a controller; do not assume GetController() is valid on the duplicated instance.
  • Overriding without calling Super will skip CopyProperties entirely, so the inactive state will be empty and seamless travel restoration will silently lose data.

Signature

virtual class APlayerState* Duplicate()

Return Type

class APlayerState*

Example

Override Duplicate to spawn the correct subclass C++
APlayerState* AMyPlayerState::Duplicate()
{
    // Let the engine spawn and copy, then cast to add subclass data
    AMyPlayerState* NewState = Cast<AMyPlayerState>(Super::Duplicate());
    if (NewState)
    {
        NewState->CustomInventorySnapshot = CustomInventorySnapshot;
    }
    return NewState;
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.