Unreal Engine 5 · Blueprint → C++
Spawn Actor From Class in Unreal Engine 5 C++
Spawn Actor From Class maps to the templated GetWorld()->SpawnActor<AActor>(ActorClass, Location, Rotation, SpawnParameters), which instantiates an actor at runtime.
Blueprint node & C++ equivalent

private:
// The actor class needs to be set in blueprint
UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
TSubclassOf<AActor> ActorClass;AActor* SpawnedActor;
FVector Location;
FRotator Rotation;
FActorSpawnParameters SpawnParameters;
if (ActorClass)
{
SpawnedActor = GetWorld()->SpawnActor<AActor>(
ActorClass, // Actor class
Location, // Spawn location
Rotation, // Spawn rotation
SpawnParameters // Spawn parameters
);
}Set up the actor class reference
Declare TSubclassOf<AActor> ActorClass as a UPROPERTY(EditAnywhere) so the class to spawn can be assigned in the editor. The TSubclassOf template restricts the picker to AActor subclasses and keeps the spawn type-safe.
The C++ equivalent
Call GetWorld()->SpawnActor<AActor>(ActorClass, Location, Rotation, SpawnParameters). Pass an FVector location, an FRotator rotation, and an FActorSpawnParameters struct that controls options like the owner and collision handling. The call returns the newly spawned AActor*, or null if spawning failed.
Wrap the call in if (ActorClass) so you never spawn from an unset class, which would return null.
Common mistakes
A common cause of a null return is collision handling: if the spawn location overlaps existing geometry, the default collision policy can block the spawn. Set SpawnParameters.SpawnCollisionHandlingOverride to ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn when you need the actor to spawn regardless.
Frequently asked questions
How do I spawn an actor in UE5 C++?+
Call GetWorld()->SpawnActor<AActor>(ActorClass, Location, Rotation, SpawnParameters) with a TSubclassOf<AActor>. It returns the spawned AActor* or null.
Why does SpawnActor return null?+
Usually the class is unset or the spawn location collides with existing geometry under the default collision handling. Adjust FActorSpawnParameters::SpawnCollisionHandlingOverride to force the spawn.