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
-
Add an EntityComponent to the root GameObject of your player.
- Select player from the
Entity UIDdropdown - Make sure
Available for Interactionis checked
- Select player from the
-
Add a CombatDamage component to the player’s weapon GameObject.
-
Drag the GraphObject you created into the
Graphfield of the CombatDamage component. -
Drag the player’s EntityComponent into the
Dealer Entityslot underOptional Referencessection. -
Enable
Enable Physics Detectionunder thePhysics Detectionsection. -
Set
Detection ModetoTrigger Collider.- Click all red
Auto Fixbuttons if any are shown.
- Click all red
-
In the
LayerMaskfield, select the layer used by your enemy prefab. -
In the
Tag Filtersection, add a new tag:hostile
Enemy Setup
-
Add an EntityComponent to the root GameObject of your enemy prefab.
- Select the corresponding enemy entity from the
Entity UIDdropdown
- Select the corresponding enemy entity from the
-
Add a
Capsule Collider(or any suitable collider) to the enemy and checkIs Trigger.
Test the Damage
- 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.
Trigger Damage via Animation (Recommended)
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