How to Create Game Objects using Tiled2Unity?


Hey @Seanba I had a question about using object layers and importing tiles as GameObjects into Unity and have been having trouble since many of the links and videos that I have tried to use, use some outdated things in them. I understand that creating an object layer using tiles (I use automapping to make this easier) will create corresponding GameObjects in Unity when imported through Tiled2Unity, but whenever I try to assign types and custom properties, I get the error that says something like (“Layer (insert layer here) is not defined”) when I import. I understand using the custom importer to automate attaching scripts and reading custom properties, but something I am doing is wrong and I can’t figure it out for the life of me. I am making a TBS tile game and so I thought that having a bunch of gameobjects for tiles that I can iterate through for A* path-finding and terrain effects would be the best/easiest method so fully understanding this process is crucial for me. Any help would be appreciated (and if anyone else has dealt with/resolved this or a similar issue, please let me know how you went about it). Thanks in advance!

(Seanba) #2

Hi monUnity, it sounds like you don’t have those layers defined in your Unity project. In Unity, select the Edit -> Project Settings -> Tags and Layers menu item. In the the inspector, expand the Layers list and add layers that match what you used in Tiled as your collision type layers.


Thanks for the quick reply! I think I might have explained it a little wrong in my first post. I was reading your post on another site about using the custom importer to attach a script to these prefabs/objects when they are imported and made a custom property called AddComp. Then I wrote something like this:

    public void HandleCustomProperties(UnityEngine.GameObject gameObject,
        IDictionary<string, string> props)
        // Simply add a component to our GameObject
        if (props["AddComp"] == "EnemyTent")

I don’t actually quite understand where the error layer is coming from (I assigned layers using the unity:sortingLayerName custom property, but the errors I’m getting back seem to stem from my AddComp custom prop.). I don’t mean to bother you too much since I know you don’t do this full time, but I definitely appreciate your help!


ahhhhhhh wait, so for every different object type I make in tiled, i have to make a layer that matches up with that object’s name?

(Seanba) #5

Yes, but that should only be the case if you are using Rectangle, Polygon, Polyline, or Ellipse objects in Tiled as these are exported as BoxCollider2D, PolygonCollider2D, EdgeCollider2D, and CircleCollider2D game objects in Unity. Are you using Tile Objects? That’s something I may have to look into.


Yeah, I’m using tiles as tile object so that I can sort them in unity as gameobjects (put them into an array for pathfinding, access tile-specific properties, etc.). I was previously using tile layers but since it’s imported as one big mesh/thing I didn’t know how to access each tile individually. I know it is usually not good practice since too many game objects can slow down the engine but I’m making smaller maps so I figured this would be best for me! Thanks again for the help, I figured most of it out now!

(Seanba) #7

Okay, I just confirmed that tile objects work as expected but IIRC that may be something I recently fixed. What version of Tiled2Unity are you using?


I think the newest version, I downloaded it maybe 2 weeks ago?


Honestly, I think it’s working fine, I just assigned different tile types to different layers and I’m just gonna sort through them that way! Haha, it might not be the best, but it should work. Just to confirm, the only way to import every tile as a separate game object is to place them all as objects in an object layer, right? Just want to confirm my understanding

(Seanba) #10

Actually, it was just 2 days ago that the version of Tiled2Unity went out that has the fix I have in mind. If things are working for you that’s okay.

And yes, you’ll want to use Tiled Objects on Object Layers in Tiled in order to have tiles exported as separate game objects.


Oh wow, I’ve been killing myself and there was a new version out! Thanks anyway Sean, you’ve been a huge help! Have a great night!