Detect melee hit

Haytam95

Active member
I'm implementing my custom health system, and i'm listening for the "OnObjectImpact" event to detect whenever the character gets hit.

Here is my custom script that handles the event:

C#:
protected void Awake()
{
    propertiesManager = GetComponent<PropertiesManager>();
    health = (IProperty<float>) propertiesManager.FindPropertyByName(healthPropertyName);

    EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact",
                                                                                      OnCharacterHit);
}

private void Update()
{
    currentHealth = health.GetValue();
}

private void OnCharacterHit(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker,
                            object attackerObject, Collider hitCollider)
{
    print("Damage received");
    health.SetValue(health.GetValue() - amount);
}


But the method isn't called.


Here is my debugging:

MeleeWeapon invokes correctly the event

1577036438852.png


But my custom file (Character Health) isn't getting called

1577036479830.png


I'm missing something? (I'm not using at all the default Health system)
 
Your breakpoint is on the old event so that won't be called. The next event is what uses the new parameters and should be called as long as you are registering the event on the hit GameObject.
 
Okay, so i just commented that line, then narrow down the debugging to "ExecuteEvent" method and GetActionsList is returning null.

1577103304687.png


Also i just changed the subscription into the Start method, without any luck

1577103536074.png


Strange, because if a keep the subscription in both methods, then a warning appears implying that the script is already subscripted. So that is working just fine.

The script is added in the gameobject in the same place UCC places its Health and Attribute system. Maybe what is failing is that the hit is detected in a child object and not in the parent? I'm just tossing ideas
 
Last edited:
Maybe what is failing is that the hit is detected in a child object and not in the parent?
That could be it. When the event is executed you can inspect what the hit object is and ensure it matches the GameObject that was registered.
 
That could be it. When the event is executed you can inspect what the hit object is and ensure it matches the GameObject that was registered.

Is there any way to propagate the event to the parent, or listen for events in the children from the parent? Or should I do a custom script for that?
 
Is there any way to propagate the event to the parent, or listen for events in the children from the parent? Or should I do a custom script for that?
There isn't a built in way but when you are registering for the event you could loop through all of the children.
 
Top