SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

[Bug] When the map is set to infinite, the layer custom property is not set to children.

Open Snowdrama opened this issue 5 years ago • 1 comments

When using a non infinite map, the output applies the unity:layer correctly In this example my map is non infinite and when importing it works correctly setting the layer of the object with the PolygonCollider2D to the layer "Wall" as expected. image

However when toggling the map to infinite and doing map chunks, the layer is no longer applied and the layer is instead set to Default image

Current workaround is to copy the layer down using a custom importer.

using UnityEngine;
using SuperTiled2Unity;
using SuperTiled2Unity.Editor;

public class InfiniteTerrainLayerFix: CustomTmxImporter
{
    public override void TmxAssetImported(TmxAssetImportedArgs args)
    {
        SuperMap map = args.ImportedSuperMap;
        foreach (Transform grid in map.gameObject.transform)
        {
            foreach (Transform gridLayer in grid)
            {
                Layer setLayer = gridLayer.gameObject.layer;
                foreach(Transform chunk in gridLayer.transform)
                {
                    foreach(Transform collider in chunk.transform)
                    {
                        if(collider.GetComponent<PolygonCollider2D>() != null)
                        {
                            collider.gameObject.layer = setLayer;
                        }
                    }
                }
            }
        }
    }
}

Snowdrama avatar Nov 04 '20 07:11 Snowdrama

@Seanba I'm a little surprised to see the chunks being set up as separate game objects. I was under impression that the Unity Tilemap object was essentially infinite, so it should be possible to simply read all chunks into the same object. Or is there some benefit from having separate game objects?

bjorn avatar Nov 04 '20 14:11 bjorn