Collider not getting Health component

I have an interesting problem. I created two weapons, one on Right hand, like in tutorial and another is the head (I’m using a different model and the attack is a Vamp bite). The right hand works fine, like in the tutorial, but the head attack doesn’t work.
It enters OnTriggerEnter, but Health components gets returned as null

Weapon handler on player:


and on the Animations, I am calling respective functions enable/disable.

It’s possible that the collider you are colliding with is not the one you expect. It will only find the Health component if it’s on the same game object as the collider you collided with.
What you can do is to Debug.Log( to see exactly which game object the collider sits on. This will likely not have a Health component, in which case you’d either go down the tree to find it (other.GetComponentInChildren<Health>()), or up the tree (other.GetComponentInParent<Health>()) depending on where the correct game object is in relation to this one.


Here is what I see in the debug. For every attack, it registered two collisions, one Targeter and one Cube and it seems that when it hits the Cube, it finds the Health component and does damage, but on the last attack it only sees Targeter and not Cube.

I’m guessing Targeter is the own collider, so that is ignored. Does the knockback not push the target out of range? I’ve had that happen with mine. The first two attacks pushes the target out of range of the third. The other option may be that the collider on the third attack has not left the cube’s collider, so it won’t register a collision. To test this you could update the Debug.Log to be Debug.Log($"Enter: {}");, and then add another method

private void OnTriggerExit(Collider other)
    Debug.Log($"Exit: {}");

Then you can check if there’s an ‘exit’ for each ‘enter’

Added what you suggested, also removed force drag to 0. Now it seems to be working, although one strange thing, the exit event doesn’t occur for the 3rd attack even though it does damage.


So it was force then, apparently. Maybe I need to play around with the collider size.

We are enabling/disabling colliders and I can’t remember if a collider triggers if it becomes enabled while inside another collider. I do vaguely remember that it does not call the exit message if it becomes disabled while inside a collider. So, the behavior where it’s not ‘exiting’ at the end is likely. It get’s disabled while it’s still in the cube’s collider

Ok thanks, I’m going to leave it at that, seems to be working now, although I will need to play around with the collider for the headbutt.

Yeah, loads of fine-tuning to get all the attacks to work like we want

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms