How to simply spawn Actor variable?

To simply spawn an Actor variable in Unreal Engine (usually in Blueprints or C++), you can follow these basic steps depending on the context:


:small_blue_diamond: In Blueprints:

  1. Use the “Spawn Actor from Class” node:

    • Right-click in the Event Graph and search for Spawn Actor from Class.
    • Set the Class input to the Actor class you want to spawn.
    • Set the Spawn Transform (Location, Rotation, Scale).
    • Optionally set Spawn Parameters if needed.
  2. Store the spawned Actor in a variable:

    • Drag off the return value of the Spawn node and promote it to a variable.
    • This is your Actor variable.

    Example:

    Spawn Actor from Class → Promote to Variable → "MySpawnedActor"
    

:small_blue_diamond: In C++:

FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = GetInstigator();

FVector SpawnLocation = FVector(0.f, 0.f, 100.f);
FRotator SpawnRotation = FRotator::ZeroRotator;

AMyActor* SpawnedActor = GetWorld()->SpawnActor<AMyActor>(AMyActor::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);

Make sure AMyActor is the type of Actor you want to spawn, and that you include the appropriate header.


:white_check_mark: Summary:

  • Use Spawn Actor from Class in Blueprints and promote the output to a variable.
  • Use GetWorld()->SpawnActor<>() in C++ and store the return in an Actor pointer.

Let me know if you need an example for a specific type of Actor or use case (e.g., spawning with delay, from another class, etc.)!