Previewer Improvements with Tiled2Unity

by Seanba on March 9, 2015

Note: My Tiled2Unity utility is available for download on this page. Also, please consider contributing to Thorbjorn Lindeijer’s Patreon for continued Tiled Map Editor support.

I’ve been working on an upcoming Tiled2Unity tutorial to help people that are trying to get information for a specific tile at a specific location at runtime.

For instance, say your working on a game like Advance Wars where the game logic has a dependency on the type of tiles that make up a level (grass, trees, mountains, etc.)

Advance Wars 2 (Copyright Nintendo)

Achieving this with Tiled2Unity is done through having all the different tile types (with collisions) on separate Tile Layers and using a raycast against their generated PolygonCollider2D objects. This gives you the ability  to know which “type” of tile you are “using”. Further, I use Tiled’s Automapping capabilities so that I only manage one Tile Layer and let the Automapper take care of the rest. (More on that in the upcoming tutorial.)

The idea isn’t that difficult but the previewer in Tiled2Unity was a huge disappointment for a map with multiple collider layers. Here is a screenshot of it in action …

Can't see collisions

What a mess. There’s six different kinds of polygons in that picture (plus a bunch of rectangles to indicate sprite location) but it’s impossible to tell where they are.

So, the latest versions of Tiled2Unity has previewer options …

Right-click to bring up Previewer Options

… that allow you to select which layers are being shown in the previewer. They also allow you to choose a color for the collision polygons on a per-layer basis:

Previewer Options (Per Layer)

(BTW, the color settings are saved to file so that you don’t have to reset them every time you use the previewer. Other maps that use similar layer names will inherit these colors while previewing.)

Now we can get a much better sense of how polygon colliders are going to be created in Unity.

Much better view of collisions

We can take this one step further. The collision layers in this example (CollisionWood, CollisionMountain, etc.) make use of the unity:collisionOnly custom property. This tells Tiled2Unity that we only want collision polygons for these layers and ignores the mesh that would normally go with them.

Given this we can preview only these layers and get an even better sense of the colliders that will be created by Tiled2Unity. Notice how the blue water polygon stands out. (And yes, that’s one polygon in Unity.)

Viewing only collisions

What I like most about Tiled2Unity (and why I made it available to the public as a side-effect of my Mega Man game) is that all of this information for the map is going to be represented by just a few polygons – and not some O(N2) number of per-tile objects.

And now, it’s easier to see that in the previewer. Happy developing.

{ 4 comments… read them below or add one }

Brock March 30, 2015 at 7:44 pm

Thank you for continuing to improve Tiled2Unity!

Adam April 4, 2015 at 8:08 pm

I can’t thank you enough for your continued development of this tool!

Is there an advantage to using automapping over the terrain tool? https://github.com/bjorn/tiled/wiki/Using-the-Terrain-Tool
I thought automapping looked like it might be more powerful, but it’s so much more complicated to set up.

bryn April 6, 2015 at 6:04 pm

holy shit, you’re an amazing and beautiful person. thank you so much for T2U. <3

Thorbjørn Lindeijer April 22, 2015 at 6:36 am

@Adam The terrain tool solves a quite specific terrain tiling use-case and won’t help with this particular problem. While the automapping is indeed more complicated to set up, it is also much more versatile.

Both tools could be improved (for example the automapping could use a preview and the terrain tool could use support for roads and fences), but they will remain different tools for solving different problems.

Leave a Comment

Previous post:

Next post: