Seanba / SuperTiled2Unity

Imports Tiled files to Unity. Better than regular Tiled2Unity.
MIT License
643 stars 84 forks source link

Created Tilemap doesn't work with Tilemap Collider 2D #135

Open tmenezes opened 4 years ago

tmenezes commented 4 years ago

Each tile layer in Tiled turns into a new tilemap in Unity (Tile as Object = false). However the created Tilemap doesn't work with Tilemap Collider 2D. Nothing happens.

Looks like the Tilemap or tiles inside of it are being created in a way Tilemap Collider can't understand them or can't compute the collider for it.

Tilemap Collider 2D is pretty handy when you want all tiles from given Tile Layer (tilemap) to have a collider automatically.

tmenezes commented 4 years ago

I apparently fixed the issue by changing the GetTileData method from SuperTile class:

public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
    tileData.sprite = m_Sprite;
    tileData.colliderType = Tile.ColliderType.Sprite;
}

I introduced the missing collider type. Not sure how this impacts the whole importer. Can someone check that?

VaultKid commented 3 years ago

Thank you @tmenezes for your workaround! I wonder if @Seanba hasn't forgot about this issue.

phybros commented 2 years ago

@Seanba is this a bug? If so I can make a PR (assuming the above fix is good - it works for me)

EternalStud3nt commented 3 months ago

@Seanba Maybe it's time this gets implemented? What do you think?

Seanba commented 3 months ago

@EternalStud3nt I think adding Collider Type has an import setting for tilesets can give people what they need here in case they want to replace the colliders ST2U makes with TilemapCollider2D components. Does that sound good?

That will essentially do what @tmenezes recommended back in 2020 (geesh, sorry about the time gap).

public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
    tileData.sprite = m_Sprite;
    tileData.colliderType = <Use Import Setting>
}
EternalStud3nt commented 3 months ago

@Seanba Yup, I agree this is an easy and easily accessible option.