How to remove vertex islands from a Polygon Collider 2D?

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!

You could create seperate child objects of the sprite object and give them polyogn colliders, effectively creating a compound collider.

–

Charno, thanks for your reply. I'm aware of this solution, but as it seems Unity is able to do this within one object, I want to know how to do this myself, and especially how to edit their auto-created colliders. Not only would it be a shame if this automated functionality is actually never useful (corrections are practically always needed), but it is also quite an inconvenience that it currently demands a workaround.

–

5 Answers

5

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!

Hi rsode, You're describing how to remove a vertex, not an island of vertices. This means that either you have misread the question or you have found that Unity has been updated to make the process of removing a vertex island less tedious. I'm on mobile and can't confirm the latter. If anyone has the opportunity to confirm this in the latest version of Unity that would be most welcome.

–

In Windows just hold CTRL when in Edit Collider mode

–

You can do this by eleminating “Paths” count:

  • Go to Polygon Collider component

  • Expand “Points”

  • In “Paths” set how many “islands” (size).

Hey, this isn't working for me. When I switch the inspector to Debut, the 'Edit Collider' button disappears and the points stay greyed-out, and I can't right click on them (nor do anything at all to manipulate them, really). Could you please clarify how you got it to work? It's super weird that this isn't a base feature.

–

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.

OMG XD unity srlsy? I thought that I cant find solution for that. But I see that's the problem of IDE. What de hell?

–

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.

Thanks for the suggestion. It seems like a pretty neat asset, but unfortunately it does not change anything about the issue of this thread.

–

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 :frowning: