UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Component Module / Damage System Completed

Component Module — UGTK

Damage System

Summary

The Damage System is a comprehensive solution for managing and manipulating the damage of game objects. It provides advanced functions for applying damage, healing, controlling vulnerability, and managing events related to the object's life.


Content


Modules Dependencies

The Damage System module requires the following dependencies:

Ensure that these dependencies are correctly imported and configured in your project.

Carried inside the prefabs. These modules are not referenced by the assembly definition - the components are simply already attached to the prefabs this module ships. Remove one of them from the project and the prefab keeps its layout and loses that behaviour, with nothing in the console to say so.

Module Component, and the prefab carrying it
ComponentModule/ColliderAutoResizeComponent Mn_ColliderAutoResizeComponent (in Damageable2D)
UtilitySystems/CollisionSystem Mn_Collider3DEvents (in CollisionAttacker)

Setup

To set up the Damage System, follow these steps:

Damage Component

Depending on the type of damage to do to a target, this system provides to damage three types of targets: Collision Target, Mn_HealthComponent Target or a class that inherit by IDamageable. Use the appropriate prefab depending on your requirement

  1. Add InterfaceDamageComponent prefab, CollisionDamageComponent prefab or SimpleDamageComponent prefab to your scene:

  1. Add the corresponding Receiver of the damage, depending on the Mn_DamageUsed

  1. If you're using the Mn_HealthComponent, remember about to set the max life and the life:

  1. If you have a slider for the life, attach it!


How To Use

To use the Damage System, use the following methods:

  1. Apply Damage:

     //T can be Collision, Mn_HealthComponent, or IDamageable class
     T target;

     //T1 is any class that inherit by Mn_DamageComponent. Substitute it with
     // 1. Mn_BaseDamageComponent
     // 2. Mn_CollisionDamageComponent
     // 3. Mn_InterfaceDamageComponent
     T1 damageComponent;

     damageComponent.DamageTarget(target);

  1. Healing Mn_HealthComponent:

     float amount;
     Mn_HealthComponent healthComponent;

     healthComponent.Heal(amount);

  1. Fully Heal:

     Mn_HealthComponent healthComponent;

     healthComponent.HealTotally();

  1. Make Invulnerable:

     Mn_HealthComponent healthComponent;

     healthComponent.BecomeInvulnerable();

  1. Make Vulnerable:

     Mn_HealthComponent healthComponent;

     healthComponent.BecomeVulnerable();


Testing Scene

Open DamageSystem in the module's Debug/ folder.

What to do, in order:

Select Damageable > HealthComponent and use the Health Component Controls block at the bottom of its inspector, with the editor stopped:

  1. Press Take Damage a few times and watch Current Life fall by the damage amount each time.
  2. Press Become Invulnerable, then Take Damage again. The life does not move and the Vulnerable tick is off: that is the whole point of the flag.
  3. Press Become Vulnerable and damage again. It falls once more.
  4. Press Heal Totally, then Kill. Life goes back to the maximum, then straight to zero.
  5. Apply damage twice in the same frame from your own code.

Step 5 is the one that catches real bugs: a death event that fires twice runs the game-over sequence twice, and the second run usually happens after the first has already torn the scene down.


Technical Info

The following are the main scripts and workflow of the Damage System. Refer to the UML section for the detailed structure.

Scripts:


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 3 modules in total.