Search Unity

Question How to instantiate a new TMP_UGUI from script?

Discussion in 'UGUI & TextMesh Pro' started by a436t4ataf, Dec 30, 2022.

  1. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    * Docs have nothing on this.
    * FAQ is offline.
    * Creating a new TextMeshProUGUI from Editor - works fine
    * Creating a new TextMeshProUGUI from Script - fails; the component is created, added, but nothing renders, and the Inspector is corrupt (the 'material' section is missing), but ALL FIELDS ARE IDENTICAL to the 'created from Editor' version.

    I have tens of thousands of Text objects to create, and I'm not going to do it by hand in the Editor when it takes 30 seconds to write the script to do it for me. Except I've spent 1 hour trying to find any docs on TMP for this and debug it.
     
  2. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    ...ah. Found out hte hard way: TMP gets corrupt in some weird way if you create any TMP objects while inside UnityUI's layout / mesh-creation routines. No error messages, just ends up broken.