Multiple issues with the TextMesh component

Hi all

I’m making TextMeshes for some of my objects by duplicating the GameObject and adding a TextMesh component. This is my method:

   	private void __buildTextDuplicate()
    	{
    		this.__textDuplicate = Instantiate(this.gameObject,
    											this.gameObject.transform.position,
    											this.gameObject.transform.rotation) as GameObject;
    		this.__textDuplicate.transform.parent = this.gameObject.transform;
    		this.__textDuplicate.name = "Text";
    		
    		// Remove our components
    		Destroy(this.__textDuplicate.GetComponent<Element>());
    		Destroy(this.__textDuplicate.GetComponent<MeshCollider>());
    		
    		// Set the text material
    		Material textMaterial = ResourceManager.getResource<Material>("Materials", "text");
    		this.__textDuplicate.GetComponent<MeshRenderer>().material = textMaterial;
    		
    		TextMesh textMesh = this.__textDuplicate.AddComponent<TextMesh>();
    		
    		// Setup the text options
    		textMesh.characterSize = 0.1f;
    		textMesh.fontSize = 100;
    		textMesh.richText = false;
    		textMesh.offsetZ = 0.01f;
    		
    		Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
    		textMesh.font = Instantiate(font) as Font;
    	}

My result looks like this:

1390116--71368--$5b64803ae603b157a3810d65de782932.png

Now, there are a couple of issues here:

  1. The text isn’t alpha’d correctly. If I go into the inspector and set the font to None and then back to Arial again, sometimes it will correct itself.

  2. The text is flipped horizontally. Why does this happen? The original geometry is Y up, Z towards camera.

I guess it’s pretty clear that my approach of programatically adding text to objects is wrong. Can anyone suggest a stable way of doing this?

Thanks,
Ves

Is the textmaterial a proper font material?
I’m also not sure you need to instance the font to assign it:

This snippet turns an empty GO into a working 3d text

		TextMesh tm = gameObject.AddComponent<TextMesh>();
		tm.font = (Font) Resources.GetBuiltinResource( typeof( Font ), "Arial.ttf" );
		tm.renderer.material = tm.font.material;