Hi all,
I added a Polygon Collider 2D to an object which had a sprite.
Probably with the best intentions, Unity tried its best to create a fitting collider for me.
(The only workaround I have found for this is to copy a Polygon Collider 2D from an Empty Object. Silly, but it works.)
This time, however, I choose to let Unity do it’s thing and edit the collider afterwards. But what if Unity created more ‘islands’ then I want? I seem to have zero control over the number of islands. I cannot create them, but ever worse: I cannot remove vertices after the polygon has been reduced to a triangle.
Who knows a solution? Thanks in advance!
Click Edit Collider on the Collider component.
Hover the mouse over the bad vertex.
Hold CMD on Mac, CTRL on windows.
The vertex will become red.
Click.
Gone!
You can do this by eleminating “Paths” count:
-
Go to Polygon Collider component
-
Expand “Points”
-
In “Paths” set how many “islands” (size).
To answer my own question: I have concluded this is still not possible in Unity 5.2.2.
Edit: Still not supported in 5.4.2f2, but a workaround was suggested by @Okey92.
Hey
You might want to check this:
Unity Advanced Polygon Collider
video: Unity Advanced Polygon Collider - Simple and Easy Physics Geometry - YouTube
Maybe this will help you resolve your problems.
Cheers.
maybe deleting the path programatically as this code:
using UnityEngine;
// add this script to the gameobject that contains the PolygnCollider2D and then use "run" boolean
// checkbox
[ExecuteInEditMode]
public class NewBehaviourScript : MonoBehaviour {
public bool run;
void Start() {
run = false;
}
void Update() {
if (run == true) {
PolygonCollider2D poly = GetComponent<PolygonCollider2D>();
for (int length = poly.pathCount, i = 0; i < length; i++) {
if (poly.GetPath(i).Length == 3) poly.SetPath(i, null);
}
run = false;
}
}
}
This deletes isolated triangles, but still existing as a zero item array in the list of paths