Better Control of Tiled2Unity Files in Your Unity Project

by Seanba on June 7, 2015

Version 0.9.11.0 of Tiled2Unity has just been added to the Tiled2Unity Download Page. This build contains a couple of new features for power-users.

You Can Now Put Tiled2Unity Anywhere In Your Unity Project

I had originally hardcoded all the scripts that build a prefab from Tiled2Unity to exist at the Assets/Tiled2Unity directory. However, many developers prefer to gather all third-party libraries in a common location and I totally can’t blame them for wanting to put Tiled2Unity in a location like Assets/Scripts/ThirdParty/Tiled2Unity along with everything else. That is now supported with the latest build of Tiled2Unity.

One caveat: I had to change the way the Tiled2Unity exporter is made aware of your Unity project in order to export the right files to the right location. You will now have to explicitly select your Tiled2Unity scripts location in your Unity project instead of just selecting the project root folder. This is done by finding the Assets/Your/Path/To/Tiled2Unity/Tiled2Unity.export.txt file in your Unity project.

Tiled2Unity Exporting

The “Export To …” button allows you to choose where to export Tiled maps within your Unity project.

Each install of Tiled2Unity in Unity contains an export marker file that must be selected as the export destination.

Tiled2Unity Export Open File Dialog

You will need to traverse into your Unity project to find the Tiled2Unity/Tiled2Unity.export.txt file. This will instruct the Tiled2Unity exporter where all the textures, materials, meshes, and prefabs will be created for use in your Unity project.

This is just a tiny bit more complicated than earlier builds of Tiled2Unity but I think the trade-off is worth it. Tiled2Unity will remember your last export destination so you won’t have to select this every time you export a Tiled map into your project.

Mark Tiled Maps as Resources For Object Instantiation

Most Tiled2Unity users will simply drop a Tiled2Unity generated prefab into their scene but some developers may want to instantiate a map prefab through script. However, Unity forces developers to place such assets in a Resources folder. This meant users would need to export a Tiled map into Unity then move the generated prefab into another folder by hand — which breaks automation.

With the latest version of Tiled2Unity you can mark a Tiled map with the unity:resource property like so …

Map Property unity:resource

Add a custom property with the name unity:resource (set value of True) to mark the map as a Unity resource. This will allow you to instantiate the map prefab via script.

Normally, Tiled map prefabs are constructed in the .../Tiled2Unity/Prefabs folder but with the unity:resource property they will reside in .../Tiled2Unity/Prefabs/Resources instead. With this you can easily instantiate the prefab in realtime via a Unity script, for example …

using UnityEngine;
using System.Collections;

public class MapCreator : MonoBehaviour
{
    void Start()
    {
        UnityEngine.Object prefab = Resources.Load("MyTiledMapPrefab");
        GameObject.Instantiate(prefab);
    }
}

Developers employing some kind of procedural generated content scheme should find that useful.

Added Potential Bonus: Win32 Specific Code Removed

With this latest build I have gone through and removed all dependencies on unmanaged Win32 code (the old export dialog was a big offender). The Tiled2Unity exporter still doesn’t officially support any non-Windows platform but people wanting to make Mac or Linux versions run via Mono should have an easier time at it now.

Reminder: Tiled Map Editor has been totally free for years now. Please consider contributing to Thorbjorn Lindeijer’s Patreon for continued Tiled Map Editor support.

{ 7 comments… read them below or add one }

Benjamin P June 15, 2015 at 10:23 pm

unity:resource <—- Awesome! 🙂

James July 11, 2015 at 1:37 pm

With the new export option, I can’t seem to get the command line to work. For simplicity, say my unity project is in C:\Game and my Tiled2Unity.export.txt is in C:\Game\Assets\ThirdParty\Tiles2Unity

Well when I export manually I put the path to the export txt and it processes just fine.

When I run the command “c:\Program Files (x86)\Tiled2Unity\Tiled2Unity.exe” %mapfile C:\Game\Assets\ThirdParty\Tiled2Unity the tiled2unity window pops up with buttons enabled, but when pressing the big ass export button, I get the error:

UNITYDIR ‘C:\Game\Assets\ThirdParty\Tiled2Unity’ is not a Unity Project folder

This a bug or am I just doing things incorrectly?

Seanba sez: Hi James, that does appear to be a bug. I will get a fix up sometime this weekend. Thanks for the report and stay tuned.

Seanba sez (part deux): James, try the latest version from the download page (0.9.11.2). That should put the command line features of Tiled2Unity back in working order. Apologies of the mess.

James July 11, 2015 at 9:47 pm

That seems to have fixed it. Thanks Sean for all your hard work and for providing this to the unity community.

Rafael August 11, 2015 at 5:32 pm

Great tool man… we appreciate this.

Hakan June 26, 2016 at 10:34 am

My unity gets stuck at importing the xml file and says “Error importing texture ‘Assets/Tiled2Unity/Textures/8x8_preset4.png’. Could not find material. Try re-importing Tiled2Unity/Imported/[MapName].tiled2unity.xml file”

Seanba sez: Hi Hakan, I recently fixed some problems with texture importing. Can you update to the latest version of Tiled2Unity and try again? (Don’t forget to update your Unity-side scripts too)

Chris July 3, 2016 at 7:29 pm

I still have the same problem / error message as Hakan. I am using the Mac Version.

Seanba sez: Hi Chris, the bug Hakan reported was fixed in a recent version of Tiled2Unity. Can you try updating and see if that works for you? Thanks.

Pedro Camacho D`Andrea November 7, 2016 at 6:09 pm

Hello, my name is Pedro, and I am currently on a Game Development Marathon, with final due date to 25/11/2016.

I have used TILED and TILED2UNITY to create the level for a 2D Platformer.

All the resources are working fine inside unity, but when we EXPORT TO WEBGL, the assets get bugged, stop showing entirely or some parts of them vanish/breaks.

Any advices on a fix, PLEASE?

Seanba sez: It appears that this is a problem with some WebGL implementations when using NPOT textures. As a rule, try to always use textures that are powers-of-two (64×64, 128×256, 512×512, etc..) for your tilesets. Most platforms don’t have this limitation but it’s a real pain when it shows up.

Leave a Comment

Previous post:

Next post: