- Home /
Refreshing the Polygon Collider (2D) upon sprite change?
Let's say, in an Unity 2Dish project, that I want to draw an hole or something similar inside a Sprite. Naturally, I want to make transparent the "drawing" of the sprite, and update dinamically its related Polygon Collider.
I have an old script which worked like that: updating the sprite to transparent via setPixel and updating the sprite texture, and updating the Polygon Collider like that:
Destroy(GetComponent<PolygonCollider2D>());
gameObject.AddComponent<PolygonCollider2D>();
I remember this used to work in old versions of Unity, but I tried it today on version 5.5.0f3 and the Polygon Collider simply does not update, while I can successfully make "transparent" the Sprite where I want. How can I achieve or fix this?
Answer by starrtennis · Aug 08, 2019 at 11:35 PM
The only thing I know that routinely gets messed up after a version update is public variable references (they get reset to null). Make sure the scripts in your game objects have the correct public variables (or any at all).
I doubt this is the issue but worth a shot.
Your answer
Follow this Question
Related Questions
Can I generate a sprite for a specific collider? 0 Answers
UI Image doesn't react to OnMouseDown() 3 Answers
Dealing with Extra Large Sprite Sheets 1 Answer
Unity 2D game: all colliders not working 3 Answers
Image distorts when created in C# 3 Answers