UGameplayStatics::BeginDeferredActorSpawnFromClass
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Begins a two-phase actor spawn, returning an uninitialized actor so you can set properties before the construction script runs. Must be paired with FinishSpawningActor to complete the spawn.
Caveats & Gotchas
- • The returned actor is in an incomplete state — BeginPlay has NOT been called and neither has the construction script. Never pass it to gameplay systems before calling FinishSpawningActor.
- • UnsafeDuringActorConstruction: do not call this inside a UObject constructor or from a construction script; the engine will assert in non-Shipping builds.
- • If the returned pointer is null (e.g. due to collision rejection), calling FinishSpawningActor on null is safe (it no-ops), but you should guard anyway to avoid follow-up logic bugs.
Signature
static ENGINE_API class AActor* BeginDeferredActorSpawnFromClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, const FTransform& SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::Undefined, AActor* Owner = nullptr, ESpawnActorScaleMethod TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Object used to retrieve the world context. | — |
| ActorClass | TSubclassOf<AActor> | Class of actor to spawn. | — |
| SpawnTransform | const FTransform& | Initial world transform applied at FinishSpawningActor. | — |
| CollisionHandlingOverride | ESpawnActorCollisionHandlingMethod | How to handle spawn location collisions. | ESpawnActorCollisionHandlingMethod::Undefined |
| Owner | AActor* | Optional owning actor. Affects network relevancy and ownership queries. | nullptr |
| TransformScaleMethod | ESpawnActorScaleMethod | How the spawn transform scale combines with the actor's default scale. | ESpawnActorScaleMethod::MultiplyWithRoot |
Return Type
AActor* Example
Deferred spawn with pre-construction property setup C++
FTransform SpawnTransform(FRotator::ZeroRotator, SpawnLocation);
AMyProjectile* Projectile = Cast<AMyProjectile>(
UGameplayStatics::BeginDeferredActorSpawnFromClass(
this,
AMyProjectile::StaticClass(),
SpawnTransform,
ESpawnActorCollisionHandlingMethod::AlwaysSpawn,
this));
if (Projectile)
{
Projectile->InitialSpeed = 2000.f; // set before construction script
UGameplayStatics::FinishSpawningActor(Projectile, SpawnTransform);
} Tags
Version History
Introduced in: 4.8
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?