# Register a Weapon and Land a Melee Hit

> For the complete documentation index, see [llms.txt](llms.txt).

Give the player a sword that hits a practice target only during the swing. Start with two [combatants](cbt-first-steps.html) and a swing montage that plays on the character.

Procedure: Register the sword

1. Create a Blueprint based on `NinjaCombatWeaponActor`. Give it a mesh and add a socket named `sScan` near the middle of the blade. Return this mesh from `GetMeleeMesh`. Give the weapon an identifying gameplay tag such as `Combat.Weapon.Sword`.

2. Add `NinjaCombatWeaponManagerComponent` to the character and return it from `GetWeaponManagerComponent`. Add the sword Blueprint to Default Weapon Classes. In Weapon Socket Mapping, map that class to a hand socket that exists on the character mesh.

Procedure: Time the hit to the swing

1. On the swing montage, add a Melee Scan notify state covering the contact frames. In the notify's Request Data, select Weapon as the source and give Weapon Query a rule matching the sword tag. Select Box Sweep, enter `sScan` as the scan socket, and size the box to cover the blade. Use the combat trace channel from your collision setup.

2. Create an ability based on `CombatAbility_MeleeAttack`. Keep the melee attack trigger on Gameplay Event, assign the swing montage, and set its melee damage effect to a child of `CombatEffect_MeleeHit`. Give the attacker positive Base Damage.

3. Grant the ability to the player. For a first test, call Try Activate Ability by Class on the player's Ability System Component from a button press. Enable debug on the attack ability so you can see the sweep.

![Melee Scan configured to sweep a socket on the selected weapon](Documentation/cbt_guide_melee_animation_scan_weapon.png)

## Use the Same Move for an Unarmed Strike

For a punch, implement `ICombatMeleeInterface` on the character and return its mesh from `GetMeleeMesh`. Select Owner on the notify and use a sphere sweep at a hand socket. If the character already has a dedicated hit shape, return it from `GetMeleeOverlap` and select the overlap scan mode.

For a weapon with its own hit effect, implement `GetHitEffectClass` on the melee source. To react after an effect was applied, override `HandleMeleeGameplayEffectApplied` on the ability in Blueprint or `HandleMeleeGameplayEffectApplied_Implementation` in C++. The hit result identifies the target and contact point.

## Try It in Play

Swing once in range and check that the target loses health during the scan. Swing again just out of reach. The montage should still play and the target should keep its health. If the box appears at the wrong location, inspect the socket on the mesh returned by the melee source.

