Give an Object Health

Give an Object Health

๐ŸŽฏ Goal

Make a player, enemy or prop take damage and die.

๐Ÿงฐ What You Need

  • A GameObject with a collider
  • Health

๐Ÿชœ Steps

Add Health

Select the root of your object and add Add Component > Glowing Rifts > Modular Health > Health. Put it on the root, not on a child, so every collider in the object can find it.

Set the starting health

Set Health to a value, for example 100. It is both the starting health and the maximum: healing never goes above it.

Choose what happens on death

Keep Destroy On Death on for enemies and props that should disappear. Turn it off for a player you want to respawn, and handle death yourself (see Handle Death and Respawn).

Test it

Hit the object in Play mode. The quickest way is the ready-made Damage prefab from Glowing Rifts/Modular Health System/Health: it takes 100 health from anything it touches. Drop one above your object, turn on Use Gravity on its Rigidbody, and press Play to watch it fall and hurt the object.

๐Ÿ“ Inspector Settings

FieldWhat it doesSet it to
HealthStarting and maximum health100 for a player or enemy, more for a boss
Destroy On DeathDestroy the GameObject when health reaches zeroOn for enemies and props, off for players
On Health ChangedRaised with health from 0 to 1A health bar
On Damage Data ReceivedRaised with the damage or heal that changed healthDamage numbers
On DeathRaised once when health reaches zeroEffects, score, respawn

๐Ÿงช Example

The duck in the Simple Duck scene is a single object with Health set to 200 and a sphere collider, with its On Health Changed driving a health bar.

It adds a Hitbox by hand only to lower the damage multiplier to 0.2, plus a few feedback components.

๐Ÿ’ก Tips

  • An object with a single collider only needs Health. When the root has a collider and there’s no Hitbox anywhere in the hierarchy, Health adds one with multiplier 1 on Awake.
  • If the colliders are on children, add a Hitbox to each of them. Health doesn’t add one there.
  • Health changes in whole numbers: damage is rounded after modifiers, so a hit under 0.5 does nothing.
  • Use the Health prefab from the Health folder as a starting point. It’s a sphere with Health (100) and a Hitbox.

๐Ÿ”— Related