- Home /
[Solved] Bug with disabling Polygon Collider 2D
When i tried to set my polygon Collider 2d to disabled (enabled = false), it would never disable for me. Had to instead just destroy the poly collider. Does anyone else have this issue?
Probably not a bug, you're probably doing it wrong. Do you have other Collider2D Components attached to the object?
It works fine here
GetComponent<PolygonCollider2D> ().enabled = false;
I Agree!
I'm guessing he has two Collider2D
components, and is turning it off like so:
GetComponent<Collider2D> ().enabled = false;
ins$$anonymous$$d of the way you did it. If he only has a PolygonCollider2D
component, it will work either way, but if there is more than one and he uses the above way of doing it, it will simply disable the higher component in the hierarchy.
No I just have one collider on the game object. But i didn't call it like you did. I made a variable
private PolygonCollider2D coll;
and set it in start to
coll = GetComponent<PolygonCollider2D>();
then in the OnTriggerEnter2D method i put
coll.enabled = false;
Im still new at this but I thought it might be a bug because i disabled the SpriteRenderer the same way and it worked. Im sure it works if i did it the way you guys said