Change DefaultShader in Tiled2Unity


Hi, I just started using Tiled2Unity. First, it is a wonderful product, and I’m appreciative of the creator for making it and supporting it.

Whenever I export a map to Unity it gives everything on the map the default shader from Tiled2Unity. I manually change it to the Diffuse shader that Tiled2Unity included so that I can use lighting. I have a lot of things on my map and every time that I edit my map and export it again, everything resets to the default Tiled2Unity shader. How can I edit the settings so that all of my items have the Tiled2Unity diffuse shader (by default) instead of the Tiled2Unity “default” shader.

Also, if that’s possible, can I make it so that different items have different shaders by default?

I went through the files and tried manipulating some stuff but messed up and had to reinstall it. Any help is appreciated. Thank you!

(Seanba) #2

My apologies for not getting back sooner. This is the kind of thing that Custom Importers were designed for – so you can write code that changes modifies a Tiled2Unity-created prefab that you would otherwise do by hand.

For changing the shader/material via a custom importer I would add something like the following to an editor script …

class MyCustomImporter : Tiled2Unity.ICustomTiledImporter
	public void HandleCustomProperties(GameObject gameObject, IDictionary<string, string> props)
		// Do nothing

	public void CustomizePrefab(GameObject prefab)
		// Go through every rederer in the prefab and assign its shader to something else
		foreach (var renderer in prefab.GetComponentsInChildren<MeshRenderer>(())
			var material = renderer.sharedMaterial; // Might have to be renderer.Material instead?
			material.shader = Shader.Find("Sprite/Diffuse");


This worked. Thank you Sean!