Character Health (I)

(I) IMPORTANT: Understanding this section is vital to using Platformer PRO.

The CharacterHealth component is responsible for tracking and handling any damage to the character. This includes both health and lives as well as the responses to health related events like character death or game over.

Most characters will have a CharacterHeath component. To use add a CharacterHealth component to the same GameObject as your character.

Note: To take damage a character will also requires a CharacterHurtBox. Without a CharacterHurtBox a character can only be sent the Kill() message which triggers death but not damage.



CharacterHealth has the following properties:

Starting Health The amount of health the character starts with.
Max Health The maximum amount of health the character can have.
Starting Lives The number of lives the character starts with.
Max Lives The maximum amount of lives the character can have.
Invulnerable Time The time in seconds that the character is invulnerable for after they take damage.
Death Actions A list of actions to do when the character dies (for example reload the scene).
Game Over Actions A list of actions to do when the game is over dies (for example reload the menu screen). Note if your game uses a GameOver Screen then you may want to defer some (or all) Game over Actions and let the Game Over Screen handle them.
Skip Damage animations on Death If true then the damage animation will not play when the character dies (instead just the death animation will play).
Skip Death actions on Game Over If true then the death actions will not fire when the character loses their last life.


Death and Game Over Actions

The following actions can be triggered when the character dies:

RESPAWN Respawn the character at the given respawn point or the last registered respawn point if none supplied.
RELOAD_SCENE Reload the current scene.
LOAD_ANOTHER_SCENE Load a different scene as specified in the Supporting Data.
SEND_MESSAGE Sends the Supprorting Data as a message go the Supporting GameObject. Generally you shouldn't need to do this, for more customised behaviour see events below.
CLEAR_RESPAWN_POINTS Clear all currently saved respawn points.
DESTORY_CHARACTER Destroy the character GameObject. Sometimes useful if you have multiple character objects and want to load them without reloading scene.
RESET_DATA Reset all Persitable components attached to the Supporting GameObject.
RESET_SCORE Reset the score with an id defined in Supporting Data.

See events below if you wish to perform other actions on death.

Character Health Events

Like most components in Platformer PRO CharacterHealth sends a number of events which you can use to attach related behaviour (for example play a sound and particle system when the character is damaged).

CharacterHealth sends the following events:

Healed Sent when the character gains health. Includes details of how much was healed.
Damaged Sent when the character is damaged. Includes details of the damage amount, damage type and the damage direction.
Died Sent when the character dies. Includes details of the damage that caused the death (as per Damaged event).
GameOver Sent when the game ends (i.e character dies with 0 lives). Includes details of the damage that caused the death (as per Damaged event).



CharacterHealth is a Persistable so you can for example store the characters health between levels. Both current health and current lives are saved.

Typical settings for a character:

This effectively ignores health because only death causes a save. If you also want to save current health add check to the checkbox for save on scene exit.

Note that the CharacterHeath does not have an implementation for save on change. If you wish to save health data after every change, you could extend the CharacterHealth class and add a change handler to the damage methods, but this is generally not necessary.



Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk