castleDamageable Object

The EnemyMassesDamageableObject component allows any GameObject in your scene to receive damage from Enemy Masses agents. This is ideal for destructible props, doors, switches, objectives, or any interactive element that enemies should be able to attack.


Overview

This component implements the IEnemyMassesDamageable interface, making it compatible with the Enemy Masses targeting and damage system. When agents detect and attack an object with this component, it will take damage, trigger events, and optionally be destroyed or disabled.


When to Use

Use the Damageable Object component when you want:

Use Case
Example

Destructible Props

Barrels, crates, furniture that enemies can break

Breakable Doors

Doors that enemies can attack and destroy to pass through

Objective Targets

Defend objectives that enemies try to destroy

Switches/Buttons

Interactive elements that change state when damaged enough

Barriers

Walls or barricades that enemies can break down

circle-info

This component is for non-agent objects only. For damageable characters or NPCs that are part of the Enemy Masses crowd system, use the built-in agent health system instead.


Setup

Adding the Component

  1. Select the GameObject you want to make damageable

  2. In the Inspector, click Add Component

  3. Search for "Damageable Object" or navigate to Enemy Masses → Damageable Object

Required Setup

  • The GameObject (or its children) must have at least one Collider for agents to detect and target it

  • Ensure the object is on a layer that Enemy Masses agents can target


Inspector Properties

Health Settings

Property
Description

Max Health

The maximum health value. The object starts with this amount.

Destroy On Death

If enabled, the entire GameObject is destroyed when health reaches zero.

Disable Colliders On Death

If enabled, all colliders on this object and its children are disabled on death. Useful for preventing further interactions.

Disable Renderers On Death

If enabled, all renderers on this object and its children are disabled on death. Useful for making the object "disappear" without destroying it.

Deactivate On Death

An array of GameObjects to deactivate when the object dies. Useful for hiding specific parts or triggering visual changes.

Events

Event
Description

On Damaged (float, float)

Invoked whenever the object takes damage. Parameters: (currentHealth, maxHealth). Use this to update health bars or trigger damage effects.

On Death

Invoked once when the object's health reaches zero. Use this to trigger death effects, spawn loot, or notify game systems.


Public API

Properties

Methods


Examples

Example 1: Destructible Barrel

A barrel that explodes when destroyed:

  1. Add the Damageable Object component to your barrel prefab

  2. Set Max Health to 50

  3. Enable Destroy On Death

  4. Connect your explosion effect to the On Death event

Example 2: Breakable Door

A door that opens (disappears) when destroyed, but the frame remains:

  1. Create a parent GameObject for the door frame

  2. Add the door mesh as a child

  3. Add Damageable Object to the parent

  4. Set Max Health to 100

  5. Disable Destroy On Death

  6. Enable Disable Colliders On Death

  7. Add the door mesh to the Deactivate On Death array

Example 3: Objective with Health Bar

A defend objective that shows a health bar:

  1. Add Damageable Object to your objective

  2. Create a UI health bar with a script that has a public method:

  3. Connect this method to the On Damaged event in the Inspector


Custom Damageable Objects

If you need more control, you can create your own damageable objects by implementing the IEnemyMassesDamageable interface:


Tips & Best Practices

circle-check
circle-exclamation
circle-info

Multiple Colliders: The component automatically finds all colliders in children. If you only want specific colliders disabled on death, use the Deactivate On Death array to target specific child objects instead.


See Also

  • IEnemyMassesDamageable Interface - For creating custom damageable implementations

  • Agent Targeting - How agents select and attack targets

  • Damage System - Overview of the damage pipeline

Last updated