Tiled2Unity CustomTiledImporter not working as expected

It’s hard to explain in just the title what my issue is so hear me out :slight_smile:

I have used the default CustomTiledImporter code and tried to make an “Object” into a simple door. Using the following code it pulls in the door, changes it’s name to “Door (Location property)” which is what I’d expect. But when trying to add a component or do anything else with the gameObject it just does nothing. This is my code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[Tiled2Unity.CustomTiledImporter]
public class CustomImporter_Entities : Tiled2Unity.ICustomTiledImporter
{

	public void HandleCustomProperties(GameObject gameObject, IDictionary<string, string> Properties)
	{
		if(gameObject.name == "Door")
		{
			if(Properties.ContainsKey("Location"))
			{
				gameObject.name = "Door ("+Properties["Location"]+")";
				gameObject.GetComponent<BoxCollider2D>().isTrigger = true;
				gameObject.AddComponent<DoorEntity>();
			}
		}
	}

	public void CustomizePrefab(GameObject prefab)
	{
		// Do nothing
	}
}

After looking at the tutorials on the seanba website I thought I had followed them correctly… but I can’t find the problem :frowning:

Any help would be greatly appreciated thanks

If I understand you correctly your custom importer does three things …

  1. Changes the name of the “Door” GameObject to “Door(some_location)” – This part works
  2. Sets the BoxCollider2D component isTrigger property to true – Does this work?
  3. Adds a DoorEntity component to the GameObject – This part doesn’t work

I wonder if step 2 is failing. Maybe because the GameObject doesn’t have a BoxCollider2D component on it and you are therefore throwing an exception. That’s the kind of thing that should be reported in the Console output window in Unity. Are you seeing any errors there?