Dynamic GUIText Font and Material bug?

I was working with GUIText and was creating a GUIText GO through script, setting the font and text. I noticed some behavior I thought was awkward but wasn’t sure if it was a bug or expected behavior.

Here is the code I was working with:

textGO = new GameObject("bub_txt");
textGO.transform.parent = gameObject.transform;
textGO.transform.position = Vector3(0,0,.1);
	
textElement = textGO.AddComponent("GUIText");
textElement.font = FontManager.Get().GetFont("Chalkboard");
	
textElement.material = null; // Line needed to get text to be readable
textElement.material.color = Color.black;
	
textGO.active = false;

The issue comes in with the material. If I do not set the material to NULL my text becomes all mangled or comes across as a little black block. If I set the material to NULL the text comes across as I would expect it to.

Any thoughts? Should I submit a bug report?

Regards,

– Clint

Sounds weird.

This line:

textElement.font = FontManager.Get().GetFont(“Chalkboard”);

Confuses me. What is your FontManager doing?

The FontManager is returning the Font Chalkboard from a system array.

This is the script for it:

public var fonts : Font[];
private static var instance : FontManager;

static function Get() : FontManager {
	return (instance);
}

function Awake () {
	if (instance == null){
		instance = this;
	}
}

function GetFont(fontName : String) : Font {
   for(var font : Font in fonts){ 
      if (font.name == fontName) 
         return font; 
   } 

   return null; 
}

Regards.

– Clint

Strange, I tried your code and it worked fine. I recommend recreating the problem in an empty project (i.e. exceept for the needed font/scripts) and file that with the BugReport’er.

Hiya!

It worked fine because of this line:

textElement.material = null; // Line needed to get

If you take that line out then it is all messed up and gives the result I was talking about.

My thoughts are this line should not be needed.

Thanks.

– Clint

Sorry, what I meant was that I removed the line and it still worked fine. Should have been more precise.

Huh, okay…

I’ll retry and see if it is something I am not doing correctly.

Thanks for checking!

Regards,

– Clint