UGameplayStatics::SpawnActor (Spawn Actor from Class)
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: static
Description
There is no UGameplayStatics::SpawnActor function. The Blueprint 'Spawn Actor from Class' node calls BeginDeferredActorSpawnFromClass + FinishSpawningActor. In C++, use UWorld::SpawnActor<T>() directly — it is simpler and more efficient.
Signature
static ENGINE_API AActor* BeginDeferredActorSpawnFromClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, const FTransform& SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride, AActor* Owner, ESpawnActorScaleMethod TransformScaleMethod) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any valid UObject in the world (pass 'this' from an Actor). | — |
| ActorClass | TSubclassOf<AActor> | The class to spawn. | — |
| SpawnTransform | const FTransform& | Location, rotation, and scale for the spawned actor. | — |
| CollisionHandlingOverride | ESpawnActorCollisionHandlingMethod | How to handle spawn location conflicts. Defaults to Undefined (uses actor's setting). | ESpawnActorCollisionHandlingMethod::Undefined |
Return Type
AActor* Caveats & Gotchas
- • In C++, always prefer GetWorld()->SpawnActor<AMyActor>(AMyActor::StaticClass(), SpawnTransform) over the Blueprint deferred path. It spawns in one call and returns a typed pointer.
- • The Blueprint 'Spawn Actor from Class' node exposes exposed properties for initialisation before BeginPlay — this is the deferred spawn pattern (BeginDeferredActorSpawnFromClass → set properties → FinishSpawningActor). Use this only when you need to set UPROPERTY values before BeginPlay fires.
- • SpawnActor returns null if spawning fails (e.g. collision blocking with AlwaysSpawn not set, or invalid class). Always IsValid() check the result.
Example
C++ spawn (preferred) and deferred spawn for pre-BeginPlay init C++
// Simple C++ spawn — preferred approach
FActorSpawnParameters Params;
Params.Owner = this;
AMyProjectile* Projectile = GetWorld()->SpawnActor<AMyProjectile>(
AMyProjectile::StaticClass(),
MuzzleTransform,
Params
);
// Deferred spawn — set properties before BeginPlay
AMyActor* Actor = Cast<AMyActor>(
UGameplayStatics::BeginDeferredActorSpawnFromClass(
this, AMyActor::StaticClass(), SpawnTransform,
ESpawnActorCollisionHandlingMethod::AlwaysSpawn
)
);
if (Actor)
{
Actor->InitialHealth = 200.0f; // Set before BeginPlay
UGameplayStatics::FinishSpawningActor(Actor, SpawnTransform);
} See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?