Automatically setting collisions on each tile


(Ken Carpenter) #1

Hello I am using Tiled with tiled2unity for my 2d rpg game, and was wondering if there was a quicker way to set collisions on each tile much like how unity sets up colliders with a tilemap layer. as I am finding it very time consuming to setup each tile with collision in collision editor.

In Unity, by default, each tile in a tile palette is set as “sprite” collider type, and it will automatically add a collider depending on the part of the tile is the actual image (and not the transparent part) if i add a tilemap collider component to the tilemap layer.
In tiled, however, i only know how to set collision on 1 tile at a time. Is there a way to make it like unity “sprite” collider for multiple tiles without going through each tile and setting up colliders?


(魔大农) #2

In the Tilesets panel you can click the Edit Tileset button after which you can switch to the Tile Collision Editor. Is that what you are looking for?

Also, welcome to the forums! :confetti_ball: :slightly_smiling_face:


(Ken Carpenter) #3

thanks for the welcome…

I understand where tile collision editor is but problem is i have thousands of tiles and for me to go through each tile to set collision would take too much time. Is there a faster way?

In unity, it will read a tile and automatically set collider on image boundary (exclude transparent part), it is called “sprite collider type”. Is there a similar procedure with tiled?


(魔大农) #4

Ah, so you’re looking the set up pixel-perfect collider within Tiled? :face_with_raised_eyebrow:

Something akin to Inkscape’s bitmap tracer? (Not a solution)


(Ken Carpenter) #5

sorry, I am not aware about Inkscapes bitmap tracer…

To put more simply, if you had thousands of tiles how would you add collision to them? One by one using tiled collision editor?


(魔大农) #6

I’d say having thousands of tiles is contrary to the power of using tiles. You may want to ask yourself if/why you really need that much different ones. Their convenience lies within their reusability.

But if you want a pixel-perfect collision shape that is not identical to the alpha channel of the tiles you could either create separate black-and-white tiles or hide the collision within one of the color channels, making uneven values of red block objects for instance.


(魔大农) #7

For the latter approach I made this little tool years ago with which you can make all pixels in a PNG have even colors after which you can draw your collision shapes on a separate additive layer with #010101 in an image editor. The color differences are too small for the human eye to notice, but a % 2 will reveal this hidden layer to your program. This approach even allows for multiple collision layers (one on each color channel) to be embedded within your tiles. You could differentiate between platforms and impassable obstacles or block monsters where a player could pass. Note that this tool is somewhat project-specific and may need modifications to work best for you.

EvenPNG.zip (9.4 KB)


(Ken Carpenter) #8

Would there be a way to make the whole tile is there a way to make the whole tile collidable without manually drawing a box for each one?


(Thorbjørn Lindeijer) #9

Generally I would say that in such a case, you’d just want to set a boolean like “collides: true” custom property on those tiles. You can do this after selecting all the tiles you want to set the property on, so it’s pretty quick. However, I don’t know if Tiled2Unity has such a shorthand way of saying declaring a colliding tile. Does it, @Seanba?

If that is not an option, then a little bit faster way to do this is to copy the rectangle you set on one tile and then Paste-In-Place (Ctrl+Shift+V) the rectangle to other tiles. This is a little bit faster than recreating each rectangle (even with “Snap to Grid” enabled).

One problem with the above solution is that I unfortunately broke the Cut/Copy actions in the Tile Collision Editor in Tiled 1.2.1. It has been fixed for the upcoming Tiled 1.2.3, but until then the copying would have to be done from a map instead of the Tile Collision Editor.

Eventually, I hope to enable editing of tile collisions for multiple tiles at once. This is covered by:


(Seanba) #10

That is not supported but I think it could be added to SuperTiled2Unity. Isometric tiles may be a bit of a pain though :wink:


(Thorbjørn Lindeijer) #11

What about a property that can be used to enable the Unity “sprite” collider type?