Search Unity

[Solved] TextMeshPro + unity 2019.3 : the text component is not updated if referenced externally.

Discussion in 'UGUI & TextMesh Pro' started by Erenquin, Jan 29, 2020.

  1. Erenquin


    Apr 9, 2018
    See also:
    My little story trying to use TextMeshPro with Unity 2019.2:

    As I had issues with TextMeshPro and unity 2019.2 (partly my fault), I decided to try it out with the newly released 2019.3.

    • Create a GameObject (let's say "GameManager").
    • Create a script:
      • Declare a TextMeshProUGUI variable
      • Have a score int variable which is updated in one way or another
      • Update function:
      • Code (CSharp):
        1.     void Update()
        2. {Debug.Log("update score " + score);
        3.         scoreText.text = score.ToString();
    • Create a Canvas with a TexMeshPro UI object
    • ref this component in the GameManager through the Unity interface.
    • Run -> score is updated, text display is not.

    Tried with TexMEshPro 2.0.1 (official one), older 2.0.0 and preview.3 2.1.0

    Important Note:
    * attach the GameManager script to the TextMeshPro UI object.
    * set the reference to the TextMeshPro UI object via GetComponent<>
    * Run -> tadaaa: text display does update.

    As you may imagine I do not want my GameManager to be attached to a UI component, this is a non-solution.
    Last edited: Jan 29, 2020
  2. Stephan_B


    Feb 26, 2017
    I tried to reproduce the setup you have described so I must have done something wrong as everything appears to be working as expected.

    Attached is a scene and scripts to reproduce the setup I have. Please let me know where my setup might differ from yours so I can reproduce the behavior you describe and take a closer look.

    Attached Files:

  3. Erenquin


    Apr 9, 2018
    Again thanks a lot for taking this time.
    Well ... I do not know what to say.
    I tried your package and it worked perfectly (I even saw it is based on .Net 2).
    Then I tried in my project, and ... It is working perfectly.
    I have absolutely no idea of what I did differently just now compared with yesterday.

    Another issue I had at some point, I did not mention, is that the text was updating only when I stopped the game. But it happened during a small series of run and not any more afterwards.

    Just tried to reimplement the Text mesh pro in an old branch, which had the issue, and it is working perfectly as well.
    I'm voiceless ...
    Last edited: Jan 30, 2020