SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

Composite Collider 2D Issue on Import

Open MabLuxx opened this issue 5 years ago • 5 comments

I'm having an issue regarding the import process for colliders. My issue is very similar to issue https://github.com/Seanba/SuperTiled2Unity/issues/115, but only in the sense that I am also attempting to curb a massive number of game objects (900+) in my Unity scene. I do not believe the issue is linked to the collision tiles themselves.

From what I understand, Tiled replaces groupings of multiple Polygon Collider 2D's with a single Edge Collider 2D.

I think this is the class that handles that: https://github.com/Seanba/SuperTiled2Unity/blob/master/SuperTiled2Unity/Assets/SuperTiled2Unity/Scripts/Editor/Extensions/CompositeCollider2DExtensions.cs


I am able to accomplish this by having very simple shapes, regardless of the amount of tiles used to generate them.

Collision Issue 8


However, if more complex shapes with more edges are created, it results in this error:

Collision Issue 6 Collision Issue 2

After placing collision on the entire map, I noticed that some of the tiles were consolidated, but others remained as individual Polygon Collider 2D's. My guess is that the import process for converting multiple colliders into a single edge collider runs into an error and stops working partway through, ultimately not deleting the individual objects used to create a composite.

Collision Issue 9


I have made multiple attempts to identify a threshold or shape that triggers this error, but I cannot seem to find the root of the cause. Here are the version numbers I am currently working with, as well as the map properties from Tiled and collision settings from Unity:

Tiled Editor Version 1.3.2 SuperTiled2Unity Unity Package Version 1.9.1 Unity Version 2019.2.3f1

Collision Issue 0 Collision Issue 4

MabLuxx avatar Feb 23 '20 19:02 MabLuxx

I am assuming this error is generated by failing to provide a clear path between vertices when a composite collider is generated out of many smaller colliders. I have resolved this issue by better managing collider tiles. This issue may be closed unless there are further comments or issues revolving around this post.

MabLuxx avatar Apr 09 '20 17:04 MabLuxx

Could you elaborate a bit as to how you're better managing collider tiles?

ijacquez avatar Apr 15 '20 20:04 ijacquez

I'm not certain, but I believe the issue was caused by having vertices which were unable to connect with partners cleanly in order to form a clean polygon (such as harsh points). Again, I'm not certain exactly what was causing this, but I fixed it in my project by isolating an area with more complex collision shapes than the rest of the map, and re-adding collision in way that allowed for obvious polygons to generate from the tiles. I am curious to hear if anyone else has tackled this issue and if so how.

MabLuxx avatar Apr 23 '20 16:04 MabLuxx

Here's an isolated example of the bug.

In the first image the error occurs and the individual polygon colliders are not destroyed. I believe it has something to do with the shape/size of the polygons within the red box. It is my guess that unity has difficulty merging these particular shaped into a single edge collider. Collision on TMX Bug 1

The second image shows the issue resolved. This was done by removing the tiles that were causing Unity to attempt an unstable merge of colliders.
Collision on TMX Bug 2

Unfortunately I don't know if this is enough information to solve the root of the issue, but this is how I have been solving it on my end.

MabLuxx avatar May 15 '20 16:05 MabLuxx

Hi there. I suspect the problem here is the size of your map and that ST2U is trying to create a collider that has two many vertices in it. Changing your map so that is Infinite may help as that will automatically split up the map into 16x16 chunks for you.

image

Seanba avatar Feb 28 '22 03:02 Seanba