Respawning a Player

A How To Guide for respawning player characters in Unreal Engine 4.

Choose your operating system:

Windows

macOS

Linux

In most games, there comes a time when the player character is killed and you want to respawn them in the world. In this How To guide, you will learn how to set up a simple respawn system for single player purposes.

Implementation Guide

Here you will learn how to respawn a player character in a single player game in Blueprints.

Steps

Below you will find the steps needed to respawn the player in a single player game when they are killed.

The steps below are based off using the Blueprint Third Person Template project, however you can use any project you wish.

  1. Inside your project, open up your Game Mode Blueprint (we are using the ThirdPersonGameMode Blueprint).

  2. Right-click in the graph and add an Event Begin Play node, then Right-click again and add a Get Player Character node.

  3. Drag off the Return Value of the Get Player Character node and add a Cast To ThirdPersonCharacter node and connect the nodes.

    GHT3B_1.png

    You want to Cast To your Player Character Blueprint, which is ThirdPersonCharacter in this example. This will allow us to access it and determine when the player character is killed by using an On Destroyed event, at which point we can spawn a new player character.

  4. Drag off the As ThirdPersonCharacter C pin and add an Assign On Destroyed node.

  5. Off the newly added OnDestroyed_Event node, add a Delay node set to whatever time you wish to delay the respawn (optional).

    GHT3B_2.png

    Here we are Binding an Event to another Event from another Blueprint. This allows the Event in this Blueprint to fire off when the Event occurs from the other Blueprint (the OnDestroy Event from ThirdPersonCharacter). This is called an Event Dispatcher and can also be used to communicate with the Level Blueprint to tell the world an Event has occurred.

    Refer to the Event Dispatchers documentation for more information.

  6. Off the Delay node (if you added it), add a SpawnActorFromClass node and set the Class drop down to ThirdPersonCharacter .

  7. Create a new Transform variable and call it Spawn Transform , then connect it to the Spawn Transform of the Spawn Actor node.

    GHT3B_3.png

  8. Right-click in the graph and add a Possess node.

    GHT3B_4.png

    You may need to uncheck Context Sensitive for the node to appear in the menu.

  9. Connect the Return Value from the Spawn Actor to the In Pawn of the Possess node and connect the execution wires.

  10. Drag off the Target pin of the Possess node and add a Get Player Controller node.

    GHT3B_5.png

  11. Near the Event Begin Play node, Right-click in the graph and add a Custom Event and name it Respawn .

    GHT3B_6.png

    You may need to re-check Context Sensitive for the node to appear in the menu.

  12. Connect the custom event to the Cast To ThirdPersonCharacter node.

  13. Drag off the Possess node and call the Respawn event, your full graph should look similar to below.

    Click image for full view.

  14. Compile and Save then close the Blueprint.

  15. Open the ThirdPersonCharacter Blueprint, Right-click in the graph and add an Event Begin Play node.

  16. Right-click again and add a Get Game Mode node, then drag off it and Cast To MyGame (or your Game Mode).

    GHT3B_8.png

  17. Drag off the As My Game C pin and add the Set Spawn Transform node.

  18. Right-click in the graph and add a Get Actor Transform node then connect it to the Set Spawn Transform node.

    GHT3B_9.png

    This is getting the location of the player when they start the game and setting it as the respawn location.

  19. Right-click in the graph and add an F Key Event and connect a Destroy Actor node off the Pressed pin.

    GHT3B_10.png

    This is for testing purposes and will kill (Destroy the Actor) when the F key is pressed. You would more than likely call the Destroy Actor node when the player loses enough Health or some other event that would typically kill your player.

If you Compile and play in the editor, whenever you press the F key, you should disappear momentarily, then respawn at the starting location.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss