This page goes over the game cycle and respawn mechanisms.

How does respawn work?

In most platform games, your character can take damage, and eventually die if its health reaches zero. In the Corgi Engine that’s also the default behaviour. When your character takes damage, a relatively complex chain of events starts :

  • your character takes X damage, this is handled by the Health component of your character
  • it loses X health
  • if its health goes below zero, the Health component calls its Kill() method and tells the LevelManager that the player is dead
  • the LevelManager resets the level, triggering the Respawn of the player and potentially other objects within the scene

That Respawn is done by checking what checkpoint the player last reached, repositioning the player there, and also respawning all the objects registered to that checkpoint. Objects register automatically to checkpoints in the scene. If you look at any LevelManager in any of the demo scenes for example, you’ll see a “Checkpoint Attribution Axis” checkbox in its inspector. By default it’s set on the X axis. Let’s say you have a horizontal level (think Super Mario), and three checkpoints on it. Every enemy or object in that level with an Autorespawn component will, at the start of the level, register to the first checkpoint to its right. Which means that if your character dies between checkpoints B and C, all enemies it may have killed between them will respawn too.

If you want your enemies or objects to respawn, just put an Autorespawn component on them.


Checkpoints being linked by a green line in scene view while game is running.

Creating and placing checkpoints in the Corgi Engine is extremely simple. All you have to do is create an empty game object, and add a Checkpoint component to it. It should automatically add a BoxCollider2D to it. All you have to do then is change the BoxCollider2D’s size. That size will determine the zone that will trigger the checkpoint, make it big enough so that your character won’t miss it. You can also set the facing direction from the Checkpoint component’s inspector. That’s the direction your player character will be facing when respawing.

You can then position your checkpoint in your scene, and add a few more. One last thing you can do is go to your LevelManager’s inspector, and define the Checkpoint Attribution Axis. If your level is horizontal, go for X, if it’s vertical for Y, etc. When you press play, you’ll see all your checkpoints linked by a green line in the order they’ll have to be crossed.