APlayerState::OnDeactivated
#include "GameFramework/PlayerState.h"
Access: public
Specifiers: virtualENGINE_API
Description
Called on the server when the owning player disconnects. By default destroys the PlayerState; override to preserve it in the inactive array instead.
Caveats & Gotchas
- • The default implementation calls Destroy() — if you want the player to be able to reconnect and resume their state, you must override this and store the PlayerState in GameMode's InactivePlayerArray yourself (or call Super after your custom logic).
- • This is only called on the server; clients will simply see the actor become irrelevant and get garbage collected via normal replication.
Signature
virtual void OnDeactivated() Return Type
void Example
Preserve PlayerState on disconnect for reconnect support C++
void AMyPlayerState::OnDeactivated()
{
// Persist state without destroying — GameMode handles InactivePlayerArray
if (AMyGameMode* GM = GetWorld()->GetAuthGameMode<AMyGameMode>())
{
GM->SaveInactivePlayer(this);
}
// Do NOT call Super here if you want to keep the actor alive
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?