Creating A Respawn/Checkpoint System In Unity
Today I’m creating a simple respawn point system, where upon the player’s death, they respawn at the most recently passed respawn point.
--
Today’s Objective: Create a player respawn-point system, where upon the player’s death, they come back to life at the most recently passed respawn point.
The Respawn Manager:
The system is very simple, but requires 2 main classes. First, I’ll create a RespawnManager class:
The Respawn Points:
The second class is a component which needs to be placed on each Respawn Point object in the scene in order to update the stored position whenever the player touches it. I create a new RespawnPoint class:
Note: For collisions to be detected, both objects (Player and Respawn Point) need a Collider, at least one collider needs to be a Trigger, and at least one object needs a RigidBody component. The Player also needs to have the “Player” tag.
The Player:
Now that the system is done, it needs to be started. In my player health script, I set the initial respawn point on game start:
And when the player takes damage, check if they need to respawn or completely die:
Now you can have checkpoints in your game, where once the player reaches a certain point, they don’t need to redo the previous progress even if they die!