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
| Field | What it does | Set it to |
|---|---|---|
| Health | Starting and maximum health | 100 for a player or enemy, more for a boss |
| Destroy On Death | Destroy the GameObject when health reaches zero | On for enemies and props, off for players |
| On Health Changed | Raised with health from 0 to 1 | A health bar |
| On Damage Data Received | Raised with the damage or heal that changed health | Damage numbers |
| On Death | Raised once when health reaches zero | Effects, 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 noHitboxanywhere in the hierarchy,Healthadds one with multiplier1onAwake. - If the colliders are on children, add a Hitbox to each of them.
Healthdoesn’t add one there. - Health changes in whole numbers: damage is rounded after modifiers, so a hit under
0.5does nothing. - Use the
Healthprefab from theHealthfolder as a starting point. It’s a sphere withHealth(100) and aHitbox.