AActor::BeginPlay
#include "GameFramework/Actor.h"
Access: protected
Specifiers: virtual
Description
Called when the actor is fully initialized and play begins in the world. This is called after all components have been registered and initialized. Use BeginPlay for any runtime setup that requires the actor to be fully in the world.
Signature
virtual void BeginPlay() Return Type
void Caveats & Gotchas
- • Always call `Super::BeginPlay()` as the first line when overriding, to ensure base class and component initialization runs.
- • BeginPlay is called after the constructor and after `PostInitializeComponents()`. The actor is fully registered at this point.
- • For components, the component's `BeginPlay()` is called after the owning actor's `BeginPlay()`.
- • In multiplayer, BeginPlay is called on all instances (server and clients). Use `HasAuthority()` to gate server-only logic.
Example
Overriding BeginPlay C++
void AMyActor::BeginPlay()
{
Super::BeginPlay(); // Always call Super first!
// Safe to query world, other actors, or components here
UE_LOG(LogTemp, Log, TEXT("%s has begun play"), *GetName());
if (HasAuthority())
{
// Server-only initialization
InitServerState();
}
} Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?