Search code examples
xmlunity-game-enginetiled

Get a relative path in a tiled map


When I create a tilemap with Tiled, the image is attached as a not really relative path:

<image source="../../../../../source/Assets/Resources/ExTexture.png" [...]>

This works fine while in Tiled, but makes problems when I want to import the map in Unity3D with X-uniTMX. When I manually change the XML to

<image source="ExTexture.png" [...]>

it works like a charm.

Now my question is how to import tilesets in Tiled, so that I can get rid of this odd behavior.


Solution

  • The path indicates that you opened an image somewhere on your hard drive when you created the tileset. What you have to do is to copy every tileset image into the same folder that the TMX file is stored in, then create tilesets only with images stored in the same folder as the TMX file. This should result in a image source reference without a path.

    It's best if you added the TMX file to your Unity project. Then open and edit the TMX file that's now in your unity project's asset path. That way, when adding images they will automatically appear in your Unity project as well and you don't have to keep two copies in synch.

    PS: The path you referenced is in fact a relative path, no question about it. It's just relative to the path the TMX file is stored, which makes it useless for most game engines since they use their own directory structure.