RealDocs

UWorld::SpawnActor

function Engine Since 4.0
#include "Engine/World.h"
Access: public

Description

Spawns an actor of the given class into the world at the specified location and rotation. Returns null if spawning fails.

Signature

AActor* SpawnActor( UClass* InClass, FVector const* Location=NULL, FRotator const* Rotation=NULL, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters() )

Parameters

Name Type Description Default
InClass UClass* The class of actor to spawn.
Location FVector const* World location to spawn at. Null uses the class default. NULL
Rotation FRotator const* World rotation for the spawned actor. Null uses the class default. NULL
SpawnParameters const FActorSpawnParameters& Additional spawn options: owner, instigator, collision handling, deferred construction, etc. FActorSpawnParameters()

Return Type

AActor*

Caveats & Gotchas

  • In C++, prefer the templated overload SpawnActor<T>() which returns a correctly typed pointer without a cast.
  • SpawnActor can return null even with a valid class — always check the return value. Common failures: collision at spawn location, class marked not-placeable, or the world is tearing down.
  • To configure actor properties before BeginPlay fires, set SpawnParameters.bDeferConstruction = true, configure the actor, then call FinishSpawning() on the returned pointer.

Example

Spawn a typed actor at a location C++
FActorSpawnParameters Params;
Params.Owner = this;
AMyProjectile* Proj = GetWorld()->SpawnActor<AMyProjectile>(
	SpawnLocation, SpawnRotation, Params
);
if (Proj)
{
	Proj->Launch(Direction);
}

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.