RealDocs

AActor::GetWorld

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtualoverridefinal

Description

Returns the UWorld that contains this actor. This is the primary way to access the world from inside an actor — prefer it over `GWorld`.

Caveats & Gotchas

  • Returns `nullptr` if the actor has not yet been spawned into a level or has been destroyed. Always null-check the result when calling during construction or from outside game code.
  • Declared `final` — you cannot override this in subclasses. The world pointer is cached internally; calling this is cheap.

Signature

ENGINE_API virtual UWorld* GetWorld() const override final

Return Type

UWorld*

Example

Spawn an actor using the world reference C++
void AMyActor::SpawnHelper()
{
    UWorld* World = GetWorld();
    if (World)
    {
        FActorSpawnParameters Params;
        World->SpawnActor<AMyHelperActor>(SpawnLocation, FRotator::ZeroRotator, Params);
    }
}

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.