Tiled2Unity: How to choose which layer is a collider

Regarding Tiled2Unity…

When importing the minimalist-collision.tmx example file to Unity it creates a PolygonCollider2D component around the “Dark” layer from the Tiled map.

Quite simply my question is how is it decided which layer is the “collision layer”? I have looked at the layer properties and map properties but can’t find anything. I found a “Tile collision editor” under the “View” tab… but when opening the template files this is empty so I’m guessing it’s done somewhere else.

Any help is appreciated.

EDIT: woah woah woah, I just realized that you have to edit each tile to say what is a collier or not. This is illogical because you might want to use some tiles in the background that are the same as the foreground, Like in a situation where there is a foreground and dirt underneath the floor tiles, and then the same dirt tiles are behind a door that is on the wall. Hard to explain, but I have always dealt with collisions depending on the layer.

There’s several ways around this:

  • each “Tiled Layer” can have it’s own “Unity Layer” (ground, background, etc.) and your game logic can check collisions against specific unity layers
  • any “Tiled Layer” can have a custom property on it that will ignore collisions (they won’t even get exported). See unity:ignore in the help output.
  • you can write a custom importer that can further edit a prefab (and the layers on a prefab) in a way that is specific to your game logic.

I use the same tiles for both collisions and visuals-only all the time without issue.

On a personal note: Keep in mind I’ve made this tool freely available for all using my precious spare time. The source is also available if you are empowered enough the build and run your own version. “Woah, woah, woah” and “illogical” is uncool, you know?

1 Like

I know this is an old post but in case anyone else comes across it like I did, I wanted to expand on @Seanba’s answer, I’m currently using an implementation of the first method he describes.

I import the tile prefab into Unity, I set the Layer flag of the ground layer to a custom layer I’ve called Ground.
Then, whenever I want to move the character, I figure out the target position (it’s grid based, so the character moves smoothly from tile to tile), I fire a raycast from the new position, looking only at the Ground layer using a LayerMask and if I get a hit then I know it is safe to move the player. If not, I don’t allow the move.