Object Type Support Added to Tiled2Unity

by Seanba on April 17, 2016

This is an update I’ve been waiting awhile for. Recently, Tiled has been updated with better support for Object Types.

Tiled Object Types Editor

The new Object Types Editor in Tiled allows you create type templates with default properties. With Tiled2Unity 1.0.5.0 these types can automatically be broken up into distinct collision “layers”. Default properties can also be passed on to custom importers in Tiled2Unity.

Additionally, the Tile Collision Editor now allows you to set properties on an Object Group or Collision basis.

Improved Tile Collision Editor

With the new Tile Collision Editor you can assign types to each rectangle, polygon, or polyline collider you add to a tile. You can even have collisions of different types on any tile.

What doess this mean for Tiled2Unity? With earlier versions of the utility it could be cumbersome to manage the different collision types you have on your map. For example, say you had a map in Tiled that contained three different collision types …

Single Tiled Layer with 3 Different Collider Types

Even though all these tiles could be easily placed on the same Tiled layer you would be forced to put them into separate layers, each with a unity:layer custom property on them, in order for them to be exported to Unity as separate Default, Ladders, and Spikes collision objects.

Now, with the latest Tiled and Tiled2Unity, you can simply create new types in the Object Types Editor …

Adding Object Types in Tiled

Here I’m adding new object types for the kinds of colliders I’m interested in (Default, Ladders, and Spikes). The exported TMX map will result in a prefab that breaks out collider objects into these categories.

… and use those types in the Tile Collision Editor …

Setting Type in Collision Editor

Through the Collision Editor we can select the ladder tile and add a collider that uses the Ladders type. Now I can use that tile on any Tile Layer and let the export process do the rest.

… and the collision tiles will be combined into PolygonCollider2d objects of the same type for you automatically …

Preview Using Object Type Colors

Here you can see how the tiles are combined with other colliders of the same type. Note you will need to make Tiled2Unity aware of your Object Types XML file in order to use the same color scheme you set in Tiled.

This is done without the need for a custom unity:layer property. Note that the unity:layer property is still obeyed however if used. This is useful if you have a special Tile Layer that you want to force into a particular collision type.

Note that in order to see the collision type colors in the previewer that you will need to point Tiled2Unity to an Object Types XML file. I suggest you export that file (from the Object Types Editor in Tiled) to the same folder you keep your maps in and keep it updated.

Object Types XML in Tiled2Unity

You only need to set the Object Types XML file if you a) Want to see object type colors in the Previewer or b) You have default object property settings you want passed on to custom importers in your Unity project during export.

Default Object Type Properties Exported Too

Many users won’t need to worry about setting the Object Types XML when exporting their Tiled maps. However, if you want default properties to be exported with any Tile Objects to be consumed by a Custom Importer then you will need this setting.

Note: For Tiled2UnityLite users (Mac and Linux) you will want to pass the path to your Object Types XML as a command line option. For example:

Tiled2UnityLite.cs -o=/Your/Path/To/objecttypes.xml $TMXPATH $UNITYDIR

Tiled2UnityLite.cs --object-type-xml=/Your/Path/To/objecttypes.xml $TMXPATH $UNITYDIR

Bug Reports Always Welcome

I like to think I do a pretty good job of testing new features added to Tiled2Unity, but, because of reasons, the magnitude of this update is larger than normal. If you experience odd behavior or a fatal crash please send me an email so I can be aware of it.

{ 3 comments… read them below or add one }

Oliver April 19, 2016 at 11:38 am

This is so awesome. Thank you so much for adding these features!

Sinecos May 7, 2016 at 8:56 am

Thank you for adding these features and now it is more faster and better way to create colliders with layers.

Is it possible to give unity:tag (string) or unity:isTrigger (bool) or other properties in Object Type Editor for particular types?

Vy October 7, 2016 at 11:35 pm

Hi, I’m Vy. Thanks so much for this product. I an game artist and just started to build my first game, an rpg game. I am using version 1.0.7.8 and cant Help -> import Unity Package to project. The error name was Application not found. Could u please tell me sthg about it?

Seanba sez: Some development environments lose their file association for *.unityproject files. There’s really nothing Tiled2Unity can do about this since it’s an issue with your OS. However, you can always import the Tiled2Unity.unityproject “by hand” by opening your project in Unity and selecting the “Assets -> Import Package -> Custom Package …” menu item. The Tiled2Unity.unityproject file you want to import will be in your Tiled2Unity install folder.

Leave a Comment

Previous post: