"OnObjectImpact" Event not firing?

RobotGames

Member
Using the example:

/// <summary>
/// Initialize the default values.
/// </summary>
public void Awake()
{
EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, Collider>(gameObject, "OnObjectImpact", OnImpact);
}

/// <summary>
/// The object has been impacted with another object.
/// </summary>
/// <param name="amount">The amount of damage taken.</param>
/// <param name="position">The position of the damage.</param>
/// <param name="forceDirection">The direction that the object took damage from.</param>
/// <param name="attacker">The GameObject that did the damage.</param>
/// <param name="hitCollider">The Collider that was hit.</param>
private void OnImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, Collider hitCollider)
{
Debug.Log(name + " impacted by " + attacker + " on collider " + hitCollider + ".");
}


The OnImpact event never fires. I have used other events and they work fine. This is in a monobehaviour that is dropped on a char, in the root along with everything else.

EDIT: It does fire it just does not get "caught" I have placed this script on the Melee Weapon and on the target.
 
Last edited:
I dropped it on my char. I made a guy with the char creator and dropped my script on the root level, just like all the scripts. I will have to go mess with it.
 
If you already configured AI agent then it should work.
You should double check whether capsule collider component attached or not at 'Your_Character/Colliders/CapsuleCollider'
if collider is there then it should work. I also checked in my project and it's working.

Collider is required on target objects in order to detecting hit.

There is other way also apart from registering-de registering events.
If you configured items to player character, then locate your item in hierarchy - 'Nolan/Items/Your_Item'
Find 'Shootable Weapon' component, mention 'Damage Amount' under Impact section. By default it is 10. (you can set it as per your requirement)

In order to do damage to enemy, you will require to add 'CharacterHealth' component on the enemy. For quick testing set 'Deactivate On Death' to true. (if you configured AI character with character manager dialog, then this component will already be there)
 
When the event is executed is called it is being called on the hit collider's GameObject. Maybe you have the script higher up in the hierarchy compared to what is being hit?
 
1379

Here is how I have my char.

1380

Here is output. Only the "OnHealthDamage" is being called. "OnObjectImpact" is not called but is registered in Awake. Its weirding me out. I was going to use them to add weapon modifiers but as we know they return the char that did the damage not the weapon.

I did step through the code and while "OnObjectImpact" is executed the subscriber never catches it.
 
Dammit!!!! The event I am looking for is not global. I reread the events section of the documents and found that the event I am listening for is not Global. I added my own Global event fired by the MeleeWeapon script to achieve my ends. However a global event is picked up by every subscriber. This is going to take more thought.

Is there a way to use the EventHandler to send an event to a specific object? Like you can with the Unity Object.SendMessage? A global Event is picked up by everything, a non global event is apparently only on the object that generates it.
 
Last edited:
OnObjectImpact is local to the GameObject. It looks like you have the component attached to the main character but the event is being fired on the collider, which is likely the capsule collider beneath the main character GameObject.
 
I had teething issues switching to EventHandler but key was to pay close attention to the object used. Components are objects but not GameObjects.
 
Top