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.

{ 7 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.

Cody December 11, 2016 at 11:17 pm

Hey Sean, I love your Tiled2Unity utility (from what I’ve seen in YouTube tutorials and your blog posts) – thanks so much for your hard work. I’ve just started using it with Unity 5.5.0f3 and have noticed quite a few deprecation warnings. After automatically upgrading, I’m still left with some warnings – which another user has already opened a github issue for: https://github.com/Seanba/Tiled2Unity/issues/71

Just wanted to drop you a line and see if you are aware. Thanks again for your utility, I will make sure to support via donation once I have the opportunity to use it!

Afmordeav February 22, 2017 at 8:16 am

Hey there Sean!

Hope you’re doing great, here i have a (silly) question, working with the object layers and types i had no problem exporting to unity, but how do i actually access the custom properties from the unity editor? ( i think it would be great if they appear at the gameobject properties at the inspector) Unity is recognizing my object types as layers but it doesn’t show me the custom properties y created on Tiled. Am i doing something wrong? (It would also be grate to be able to connect custom properties like Tag, to the inspector property on unity called Tag).

Again thanks for your time and energy ☼

Bless!,
Afmo

JamesK March 25, 2017 at 10:08 am

Hey Sean, thanks again for the great job you’ve done with this tool. I was going to report the issue with the collision polygons not always generating correctly (with diagonals in my case) but it looks like you just fixed it in 10.0.10.1. So thanks!

Might I recommend a small change for your next update? I was getting a namespace collision with the new SpriteDepthInMapEditor class, as it inherits ‘Editor’. Your other classes use ‘UnityEditor.Editor’ so they don’t collide. A minor issue, I know.

Seanba sez: Hi James. I just submitted this small fix but it may take a week or two before it is deployed with a build. Thanks.

Omer July 31, 2017 at 6:42 am

Hey Sean,

I have a problem (similar to Afmordeav I think) with ObjectTypes. I have a few custom properties assigned to my ObjectTypes. But when Unity imports any object with a custom type assigned, it is recognised automatically as a layer. When that layer isn’t defined in Unity, whole process fails.

As far as I can see, the problem lies in that “Type” is assigned as “layer” attribute in the exported xml. So there isn’t any solution in trying to fix this in Unity (other than doing a null check for the Unity layer perhaps?).

Am I missing something here? Thanks in advance.

Leave a Comment

Previous post: