Scorer not counting collision with original dropped object

When the player collides with the dropped object specifically, the score does not increase.
However, in the Inspector, I can see that the object does change tag to “Hit”. I assume the issue is in the order Unity is processing the scripts?

I have seen this topic from a while ago, and tried adding the relevant scripts to the Script Execution Order with no success. Interestingly, I tried using OnCollisionExit which resulted in two hits being counted for the dropped object.
My script is saving in the correct location, and if I create new objects to drop and apply rigidbody + the dropping and objectHit scripts, they do register as having been hit by both the scorer and the tag.

While the obvious solution is “just make new dropped objects”, I’m curious as to why the first one hasn’t worked properly despite being identical. Is there an explanation or is it just a strange quirk?

Hi,

How do you know that “the” score does not increase? If the tag changes, your code obviously did something during runtime. Maybe you are looking at the Inspector of the wrong game object or a prefab?

Here is the original object after being hit. It has turned pink and received the “Hit” tag after being collided with, but no other message has appeared in the debug log.

Then I hit another newly created object with identical scripts and rigidbody.


Note that one collision has registered, despite two objects now having the Hit tag and having changed colour.

I hit the capsule, weirdly the same as the first dropped object.

Then I hit another object- this time, it is a duplicate of the original object I was having difficulty with:


Hit is registered both in the new tag and by the scoring script. I tried duplicating the capsule object, same outcome. Original object isn’t scored, but the copy is. Both become Hit and change colour.

So you are right that the code has done something, but as far as I can tell, seems to be inconsistent in which objects it applies to.
As I hope the images demonstrate, I am looking at each individual game object.

…and, having moved on to the next lecture, even the newer objects no longer register.
Objects without rigidbody still register, as well as the cube. However, every sphere and capsule object eventually changes to registering the tag, but not the score in debug.

Which version of Unity do you use?

And which collision method do you call? Did you double check that the first “Falling Asteroid” has got the “Untagged” tag?

If you used OnCollisionEnter, make sure the collider does not touch the “target” collider yet because, otherwise, the “enter” collision event won’t happen.

I am using: 2021.2.6f1
I believe the latest?

I’ve used OnCollisionEnter, my script is the same as the one used in the lecture.
Everything starts as “Untagged” except the player.

Script for scorer (which is not recording in Debug.Log for these objects, but does for a time when a new one is created, and always for static objects as well as the rigidbody cube)
image

Script for changing the tag and colour of objects which collides. This works all the time.
image

Any idea as to what’s going on?
Thank you for your continued patience and support. :slightly_smiling_face:

Maybe the problem is caused by the arbitrary execution order of scripts in Unity. If the code in the ObjectHit object gets executed before the Scorer code, the tag would already be “Hit” when the if-condition in the Scorer object gets checked. Add a Debug.Log to the ObjectHit class to figure out more.

And if my theory is true, simply add the scripts to the following list. The Scorer class must be executed before the ObjectHit class. The numbers in the list don’t have any inherent meaning except for defining the execution order.

I’ve had the same problem.

Changing the Script Execution Order settings didn’t help.

However, after changing the Y value of Position Transform (raising the Player object slightly higher above the Plane), suddenly the behavior has changed and the Scorer started to run before the ObjectHit.

Good job on solving the problem. It might be that the player collider was “stuck” in the ground collider. Rising the player was a good idea. :slight_smile:

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

Privacy & Terms