Not getting Health Component

Hi all,
I’m having a problem regarding the RPG Combat Health Component.
( Unity 3rd Person Combat & Traversal > Melee Combat > Dealing Damage)
I saw there was a similar thread recently (21 days ago) however I cannot seem to solve it.

I checked to see if the Component is getting fetched (TryGetComponent) by adding a debug log after the conditional.
It never triggers.

I did what the previous thread suggested
and added debug logs for enter and exit (which are being logged)
and removed drag to 0 so it will trigger all exits and enters properly.

Here is my WeaponDamage script:

My Health script:

Here is the console log (with drag 0):
image

here is my Weapon setup:

The health script is on the same layer as the target (cube, sphere ) collider as suggested in previous post:

Any suggestions would be much appreciated,
Thanks and all the best :pray:

Add a Debug.Log to the conditional that checks if the collider is in the alreadyCollidedWith list. You never remove anything from that list so it may be in the list and therefore exits the trigger early. Thus far, it’s the only thing I can see that may cause this

Hi bixarrio thanks for the reply,
The list is being cleared OnEnable (the weapon is being enabled and disabled with each swing via Animation events).

But just to double check, added this:
image

and the console logs remain the same.

You are right, I forgot about that. Sorry.

So, let’s see; What we are finding is that the cube you are colliding with does not appear to have a Health component. Except that you’ve shown that there is one. Odd. Can you show the cube in the hierarchy with all it’s children and stuff (if there are any) expanded?

Well it has no children and it sits unparented in the hierarchy:
image

I’ve also already progressed to the enemy attack stage,
and the enemy doesn’t deal damage to me as well (he does log Enter and Exit though).

image

Oh, I see the problem. The code never reaches that part. You have a mistake here:

if (other = myCollider) { return; }

This assigns myCollider to other and then returns true, so the condition is always true and it exits the function. It should be

if (other == myCollider) { return; }

Thank you so much! :pray: :pray: :pray: :pray:

And here I was thinking I went over my code enough times.
Couldn’t figure out what’s going on

I fell for the classic :man_facepalming:

It happens. I went over that code several times and missed it, too.

1 Like

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

Privacy & Terms