I'm trying to make a series of text appear programmatically. It's not quite showing up, and I'm struggling to understand exactly why. Any ideas?

GameObject row = new GameObject("Row");
row.transform.parent = panel.transform;
HorizontalLayoutGroup rowLayoutGroup = row.AddComponent<HorizontalLayoutGroup>();
rowLayoutGroup.childForceExpandHeight = false;

GameObject name = new GameObject("Name");
name.transform.parent = row.transform;
GameObject value = new GameObject("Value");
value.transform.parent = row.transform;

Text nameText = name.AddComponent<Text>();
nameText.text = tup.First;
nameText.alignment = TextAnchor.MiddleRight;

Note that this script is run from a Panel, contained within a Canvas.

  • \$\begingroup\$ We'll need to know more about how the GameObject called "name" is set up in your scene hierarchy. Right now it could be just about anything - maybe it's out of the camera frame, or sized too small to contain the text you're giving it, or culled by a mask, layer, active, or enabled setting somewhere in the chain... \$\endgroup\$
    – DMGregory
    Jan 12, 2016 at 2:11
  • \$\begingroup\$ @DmGregory I've added more information, however, I figured out the real problem, and that was that the font wasn't included. Sigh. Well, I have it now, thanks! \$\endgroup\$ Jan 12, 2016 at 2:13

1 Answer 1


It seems the problem is that I don't have a font specified, as determined by playing with the inspector text that came out. To do that, I simply needed to add the following text to my listed code.

nameText.font= Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .