Language:
Page Info
Skill Level:
Engine Version:

Spawning/Destroying an Actor in Blueprints

Here you will learn how to spawn an Actor in Blueprints and define its spawn location. You will also learn how to destroy spawned Actors.

Spawning an Actor

Below you will find steps to spawn an Actor in the level by pressing a key.

  1. Open up any project, once inside the editor, click the Blueprints button and Open Level Blueprint.

    GHT1_1.png

  2. This will open the Blueprint Editor window (shown below).

    Click image for full view.

    In order to spawn an Actor, we will need to use the Spawn Actor from Class node. In this example, we are using the Level Blueprint, however you can use the Spawn Actor from Class node in most Blueprints where it can be found in the Palette window as shown below.

  3. Right-click anywhere in the graph and in the context menu, search for and add the Spawn Actor from Class node.

    GHT1_5.png

  4. The Spawn Actor from Class node will be added to the graph (SpawnActor for short).

    GHT1_4.png

    The Spawn Actor from Class node takes an Actor Class (specified via the Class input) and attempts to spawn an instance of that class in the world. The Spawn Transform input is used to define the Actor's spawn location in the world (and its initial orientation). If that location is blocked by a collider, then the Actor will fail to spawn unless the Spawn Even if Colliding input is set to True.

    Each of the pins on the Spawn Actor node are outlined below.

    GHT1_6.png

    Number Description
    Execution Input (1) This is an execution input and is what triggers the node to spawn an Actor.
    Class (2) This is the Actor Class you want to spawn an instance of in the world (this is required).
    Spawn Transform (3) This takes in a Transform used to position and orientate the Actor in the world.
    Spawn Even If Colliding (4) Determines if the Actor should be spawned when something is blocking the spawn location.
    Execution Output (5) This is an execution output and leads to script that should occur following the Spawn Actor.
    Return Value (6) This outputs the new Actor instance that is spawned in the world.
  5. Click the Class drop-down menu and then select an Actor from the list of Actors you want to spawn.

    GHT1_7.png

  6. After selecting the Actor you want to spawn, the node will update and a new pin will be added.

    GHT1_8.png

    The Instigator is optional and is the Pawn responsible for damage done by the spawned Actor.

  7. Left-click and drag off the Spawn Transform pin to the left, then in the context menu search for and add Get Actor Transform.

    GHT1_9.png

    The Get Actor Transform node is telling the Spawn Actor where to spawn the new Actor we want to spawn.

  8. Left-click and drag off the Get Actor Transform pin, then in the context menu search for and add Get Player Character.

    GHT1_10.png

    This is now saying, Get the Player Character then Get their Transform and assign that to the Spawn Transform.

  9. Right-click anywhere in the graph, and in the context menu, search for and add the F Key Event.

    GHT1_11.png

  10. Connect the Pressed pin to the Execute Input pin of the SpawnActor node.

    GHT1_12.png

    This now says, execute the SpawnActor when F is pressed and spawn the Actor at the Player Character's Transform.

  11. Click the Compile button then close the Blueprint.

    Before Compile:

    GHT1_13.png

    After Successful Compile:

    GHT1_14.png

    If you do not see the green check mark, verify that all your nodes are connected and an Actor Class is specified on the SpawnActor node.

  12. From the main window, click the Play Button to play in the editor.

    GHT1_15.png

    Whenever you press F, the Actor you selected should spawn where the player character is in the world.

This example illustrates spawning an Actor through a key press, however you could use any number of Events to execute the SpawnActor node.

Refer to the Specialized Node Groups for more on working with Blueprints.

Setting a Spawn Point

If you want to spawn an Actor at a specified location, you can do this by setting the Transform manually or by referencing another Actor's Transform.

The examples below will show you how to manually set a Transform as well as reference an Actor's Transform to use as a spawn location.

  1. Open up any project, once inside the editor, click the Blueprints button and Open Level Blueprint.

    GHT1_1.png

  2. In the graph window, Right-click and search for then add the Spawn Actor from Class node.

    GHT1_5.png

  3. On the SpawnActor node, click the Class drop-down menu and select an Actor to spawn.

    GHT1_7.png

  4. Minimize the Level Blueprint window.

  5. From the Main Editor window, under Modes, search for Target and drag a Target Point into your level.

    GHT1_16.png

  6. Return to the Level Blueprint window, then Right-click in the graph and choose Add Reference to TargetPoint.

    GHT1_17.png

  7. Left-click drag off the out pin of the newly added node and search for and add Get Actor Transform.

    GHT1_18.png

  8. Connect the Return Value of the Get Actor Transform node to the Spawn Transform in pin.

  9. Right-click in the graph and search for and add the F Key Event, then off Pressed connect it to the SpawnActor.

    GHT1_19.png

    We used a Key Press Event to execute the SpawnActor node, however you can use any method you wish.

  10. Compile then close the Blueprint and play in the editor, you should see your Actor spawn at the Target Point.

In addition to specifying a spawn point by referencing an Actor, you can manually enter the Spawn Transform for the SpawnActor as well, to do this:

  1. Drag off the Spawn Transform pin of a SpawnActor node, then select Make Transform.

    GHT1_21.png

  2. This will create a Make Transform node where you can enter the Location, Rotation, and Scale manually.

    GHT1_22.png

Destroying a Spawned Actor

Once you have spawned an Actor, suppose you wanted to destroy it (for example, maybe the player killed the Actor or picked the Actor up as a pick-up, etc.).

Below are the steps you can take to destroy a Spawned Actor in the Level Blueprint.

  1. Open up any project, once inside the editor, click the Blueprints button and Open Level Blueprint.

    GHT1_1.png

  2. In the graph window, Right-click and search for then add the Spawn Actor from Class node.

    GHT1_5.png

  3. On the SpawnActor node, click the Class drop-down menu and select an Actor to spawn.

    GHT1_7.png

  4. Left-click and drag off the Spawn Transform pin and add a Get Actor Transform node.

  5. Left-click and drag off the Get Actor Transform node and add a Get Player Character node.

  6. Right-click in an empty space in the graph, then search for the F Key Event node and connect it to the SpawnActor node.

    GHT1_12.png

  7. Left-click and drag off the Execute Out pin of the SpawnActor and add a Delay node.

  8. On the Delay node, set the duration to 3 (this is the amount of seconds to wait before we destroy the Actor).

  9. Left-click and drag off the Return Value of the SpawnActor and add a Destroy Actor node, then connect as shown below.

    Click image for full view.

  10. Compile then close the Blueprint and play in the editor, you should see the Actor spawn at the player location then despawn after 3 seconds.

As with executing the SpawnActor node to spawn an Actor, destroying the Actor can be triggered by several different types of Events based on your needs.

Refer to the Specialized Node Groups for more on working with Blueprints.