Skip to main content

Melee Damage Setup

This section shows how to apply your Damage GraphObject to a melee weapon using CombatDamage and physics detection.

Prerequisites

Before starting, make sure:

  • You already have a player character and a enemy character, a controller script, and an attack animation
  • You have created a Damage Graph GraphObject (from the previous guide)

Step-by-Step Setup

Player Setup

  1. Add an EntityComponent to the root GameObject of your player.

    • Select player from the Entity UID dropdown
    • Make sure Available for Interaction is checked
  2. Add a CombatDamage component to the player’s weapon GameObject.

  3. Drag the GraphObject you created into the Graph field of the CombatDamage component.

  4. Drag the player’s EntityComponent into the Dealer Entity slot under Optional References section.

  5. Enable Enable Physics Detection under the Physics Detection section.

  6. Set Detection Mode to Trigger Collider.

    • Click all red Auto Fix buttons if any are shown.
  7. In the LayerMask field, select the layer used by your enemy prefab.

  8. In the Tag Filter section, add a new tag:

    • hostile

Enemy Setup

  1. Add an EntityComponent to the root GameObject of your enemy prefab.

    • Select the corresponding enemy entity from the Entity UID dropdown
  2. Add a Capsule Collider (or any suitable collider) to the enemy and check Is Trigger.


Test the Damage

  1. Run the game. Whenever the player’s weapon touches the enemy:
  • The damage graph will execute
  • The enemy will take damage

You can monitor the enemy’s Health (hp) in the EntityComponent Inspector during runtime.


To ensure damage only occurs during an attack animation, use a Unity Animation Event.

Example:

public CombatDamage SwordDamageScript;

void Start(){
SwordDamageScript.SetEnable(flase); //Disable the damage on Start.
}

void OnDamageAnimation(){
SwordDamageScript.SetEnable(0.1F); //Enable the damage for 0.1 second
}

This approach gives you precise control over:

  • Attack timing

  • Hit windows

  • Combo balancing