isTrigger = false doesn't work but unticking it works

Hey all :slight_smile:

I am making an Asteroids clone and I have kind of a complicated situation to describe but really I have narrowed the core problem to a single line of code in my script:

meshCollider.isTrigger = false;

where meshCollider is an object of type MeshCollider which I have passed into the script (kinda obvious)

I am calling this code when the ship in my game crashes into an asteroid and my ship waits 3 seconds to respawn - while it is waiting those 3 seconds I set the collider to non trigger so it doesn’t keep crashing into asteroids while it’s not “alive”

The ‘problem’ itself is a bit hard to explain, but the main gist of it is that line of code seems to be affecting the collider of another totally unrelated GameObject in my game. Before my ship ever dies the other GameObject works fine. Once my ship has died once then it breaks.

The STRANGE thing is if I comment out the line and “manually” do this - as in, when my ship collides with an asteroid (The ship “dies” and needs to wait 3secs to respawn) I just pause the game (or not), untick Is Trigger, and then when my ship spawns back, i re-tick it, and the problem does not happen

I have been trying to figure this out for hours and I’ve run out of things to try, at this point I could swear it’s a unity bug, so if anyone’s got any suggestions I’d much appreciate it :smile:

Double check that your meshCollider variable is properly set.

You can use Debug.Log(“!”, meshCollider.gameObject); and it will send an arrow to the GameObject that owns the meshCollider when you click on the Debug error.

Other than that, did you set ignore collision to the meshCollider and other object? Or did isolate the part that screws up on the other object?

While meshcollider does inherit from collider, I would recommend just casting it as a collider (and making your variable of type Collider) instead. You’ll probably have less issues.

All I get in the console is this

!
UnityEngine.Debug:Log(Object, Object)
$:MoveNext() (at Assets\Ship\ShipCollisionHandler.js:23)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
ShipCollisionHandler:OnTriggerEnter(Object) (at Assets\Ship\ShipCollisionHandler.js:10)

Doesn’t seem to indicate anything about the gameobject owner?

**Edit:**Oops, right, I see, it highlights the gameobject which the script belongs to, and yeah, it’s the right one

Well there is only one MeshCollider in my entire scene so there is not really any possibility that the line affected any other objects. (And yea, meshCollider is definitely of type MeshCollider)

var meshCollider : MeshCollider;

Didn’t fix it unfortunately :frowning:

What exactly goes wrong when the other object (ie, not the ship) breaks?