RealDocs

AGameStateBase::HandleBeginPlay

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

Description

Called by the GameMode when gameplay officially begins (after StartPlay is called). Sets the internal bReplicatedHasBegunPlay flag and calls BeginPlay on all registered actors, then triggers match-started callbacks.

Caveats & Gotchas

  • This function is called server-side by AGameModeBase::StartPlay. The flag it sets (bReplicatedHasBegunPlay) is then replicated to clients, where OnRep_ReplicatedHasBegunPlay fires and triggers the same BeginPlay flow on the client side.
  • Overriding this without calling Super will prevent actors from receiving BeginPlay and the match from starting on clients — almost always a critical bug. Always call Super::HandleBeginPlay().
  • There is a subtle ordering difference: on the server, HandleBeginPlay fires before the first tick. On clients, it fires when the replicated bool arrives, which may be after one or more ticks have elapsed — do not rely on strict server/client synchrony at the frame level.

Signature

ENGINE_API virtual void HandleBeginPlay();

Return Type

void

Example

Notify subsystem when play begins C++
void AMyGameState::HandleBeginPlay()
{
    Super::HandleBeginPlay();
    // Notify any server-side subsystems that the match has started
    if (UMyMatchSubsystem* Sub = GetWorld()->GetSubsystem<UMyMatchSubsystem>())
    {
        Sub->OnMatchBegun();
    }
}

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.