Checking tag on collision not working in when built

Updated on September 28, 2019 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on September 28, 2019

I think I’m going insane. I have it check the tag of the collision for “Ground”. It works in editor, but completely ignores it when I build the game to test it. The OnCollisionEnter works, just not the tag checking.

void OnCollisionEnter(Collision col){
 Rigidbody rbdy = gameObject.GetComponent<Rigidbody>(); //declares rigidbody
 Time.timeScale = 0.1f;
 if (col.gameObject.tag == "Ground"){ //checks to see if you collided with ground
 rbdy.velocity =; //stops all rigidboy movement
 rbdy.angularVelocity =; //stops all rigidbody rotations
 dead = true; //makes you dead

The time scale change happens, but not the tag check. I tried moving the timescale change inside the tag check, and it never happened. This works when I run it in editor (so its not like I misspelled the tag), but not when I build the game. I also tried to check name on collision, nope. I though maybe the terrain collider was just being weird, so I tried it on a box, still nope. I have a normal box collider on it, not a trigger, and a default rigidbody.

What the heck is happening? Has this happened to anyone else?

  • Liked by
0 on September 28, 2019

Alright so it just works now? I guess it actually was a bug with Unity and not my code.

  • Liked by