Health

The Health component gives any object a health value. Place it on the root GameObject of the entity, such as a player, an enemy or a destructible prop.

Note

Damage reaches Health through a Hitbox on a collider, so add at least one hitbox to the object or its children.

✅ Ideal For

  • Players and enemies
  • Bosses with several hitboxes
  • Destructible props

📐 Inspector Overview

FieldDescription
HealthStarting health. It also becomes the maximum health
Destroy On DeathDestroy the GameObject when health reaches zero. Turn it off to handle death yourself, for example to respawn a player
On Health Changed (Single)Raised whenever health changes, with health from 0 to 1. Hook it to a UI slider’s value for a health bar
On Death (DamageData)Raised once when health reaches zero, with the damage that caused the death

⚙️ How It Works

  flowchart LR
    A["Hurt"] --> M["Modifiers"] --> H["Health"]
    B["Heal"] --> H
    H --> C["On Health Changed"]
    H -->|"reaches 0"| D["On Death"]
  • Hurt runs every enabled health modifier first. If damage is left, health goes down by the rounded amount.
  • Heal restores health up to the maximum. It skips modifiers, so Invincibility doesn’t block healing.
  • Health never goes below zero or above the maximum.
  • At zero, the object is dead: On Death fires once, then the object is destroyed if Destroy On Death is on.
  • A dead object ignores further damage and healing until ResetHealth() is called.

Tip

Hook On Death to a Spawnable Effect to spawn an explosion, or to your game manager to respawn the player.

🎮 Calling It From Events

These methods can be hooked to UnityEvents in the inspector or called from code:

MethodDescription
Kill()Kills the object immediately
ResetHealth()Restores full health and clears the dead state
Spawn(GameObject)Spawns a prefab at the object’s position, for example from On Death

See the Health scripting reference for Hurt, Heal and AffectHealth.