Hello Guest

Author Topic: addComponent<TextMesh>() doesn't render text  (Read 5880 times)

etoreo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
addComponent<TextMesh>() doesn't render text
« on: January 30, 2014, 09:37:10 am »
I am dynamically creating a Game Object and calling addComponent<tk2dTextMesh>() on it.... but it doesn't draw.  Inspecting it there doesn't seem to be a MeshFilter on the object - and when I manually change any value on the tk2dTextMesh object, the MeshFilter populates and the text is drawn.  I have called Commit() on the tk2dTextMesh object after creating it and it still won't draw.

Any advice?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: addComponent<TextMesh>() doesn't render text
« Reply #1 on: January 30, 2014, 11:02:43 am »
After adding the component, do you assign the font, text & Commit()?

etoreo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: addComponent<TextMesh>() doesn't render text
« Reply #2 on: January 30, 2014, 05:46:00 pm »
The font is probably my problem, thanks.  How can I get a font dynamically in my code?  I don't see a directory of available fonts.

On a related note, how might I show an tk2dFont selector in a custom Unity Editor Window?  I need something to the tune of EditorGUILayout.ObjectField so I can create my text from a wizard I am making.

Thanks a bunch!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: addComponent<TextMesh>() doesn't render text
« Reply #3 on: January 30, 2014, 10:35:05 pm »
You'll have to get fonts at runtime using Resources.Load. Its just the font data object that needs to be in resources for this to work.
The code that draws the font selector is in tk2dTextMeshEditor.cs, OnInspectorGUI. It performs lots of little checks to make sure assets are sensible.

etoreo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: addComponent<TextMesh>() doesn't render text
« Reply #4 on: January 30, 2014, 10:45:33 pm »
Thanks for the tips, I am sure this will get me where I need to go.

scott

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: addComponent<TextMesh>() doesn't render text
« Reply #5 on: June 23, 2014, 08:43:03 am »
Just encase anybody comes across this same issue, setting the font solved this issue for me - just as the original poster believed it would.