RealDocs

AGameModeBase::StartToLeaveMap

function Engine Since 4.14
#include "GameFramework/GameModeBase.h"
Access: public Specifiers: virtual

Description

Called at the beginning of a map transition — either at the start of seamless travel or immediately before a hard (non-seamless) map change. Override to save state or clean up before the current level is unloaded.

Caveats & Gotchas

  • For seamless travel, this is called on the **current** GameMode before the transition map loads; for hard travel it is called right before `UWorld::CleanupWorld`. The timing differs, so state may already be partially torn down during hard travel.
  • The default implementation is empty; call `Super::StartToLeaveMap()` for forward compatibility.
  • Do not spawn or modify actors here for seamless travel — actors added at this point will not be included in the seamless-travel actor lists that were already collected.

Signature

virtual void StartToLeaveMap()

Return Type

void

Example

Save match stats before leaving the map C++
void AMyGameMode::StartToLeaveMap()
{
    Super::StartToLeaveMap();

    // Flush any pending stat saves before the level unloads
    if (UMyStatsSaveSystem* Stats = GetGameInstance()->GetSubsystem<UMyStatsSaveSystem>())
    {
        Stats->CommitPendingStats();
    }
}

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.