Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Textmesh pro is not updating when changing text programatically

Discussion in 'UGUI & TextMesh Pro' started by Ledrec, Aug 24, 2017.

  1. TheHighlander

    TheHighlander

    Joined:
    Jan 11, 2023
    Posts:
    5
    Despite everything written in this thread, I still have no solution to my problem, but I know what I want to do at least.

    I am trying to programmatically change the Text Input value of a TextMeshProUGUI game object. My only problem now is that I do not know how to reach the TMP_InputField of the game object in my script.
    I should add that I am attempting to change the input field inside a OnCollisionEnter2D event listener

    - When I [SerializeField] TMP_Inputfield in my script, the editor will not allow me to drag a game object of type TextMeshProUGUI onto it. Makes sense. Can I drag a TMP_InputField from anywhere?

    - When I [SerializeField] TextMeshProUGUI in my script, I can drag the game object onto it, but using .GetComponent<TMP_InputField> just results in an empty object reference.

    What am I doing wrong? How do I solve this?
     
    xucian and megame_dev like this.
  2. TheHighlander

    TheHighlander

    Joined:
    Jan 11, 2023
    Posts:
    5
    Forget the TMP_InputField stuff. All I have done now is change the sprite asset reference from

    <sprite name = "sprite_name_0">

    to

    <sprite=0>

    NOTE: do not use < sprite = 0 > (with spaces) because the parser won't accept it apparently.
     
  3. Arslan_JEU_Tech

    Arslan_JEU_Tech

    Joined:
    May 17, 2023
    Posts:
    1
    i am trying to update the tmp pro text ...... because my requirement is when the player collect the coins it should be should on the next level and i am trying to implement this functionality.......
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using TMPro;
    6.  
    7. public class coincollecter : MonoBehaviour
    8. {
    9.     public int coinsCollected =0;
    10.     [SerializeField]
    11.     private TMP_Text  coinstotal;
    12.  
    13.    static int total;
    14.  
    15.     private void OnTriggerEnter(Collider other)
    16.     {
    17.  
    18.         if (other.gameObject.CompareTag("coin"))
    19.         {
    20.             coinsCollected++;
    21.             Destroy(other.gameObject);
    22.             coinstotal.text = coinsCollected.ToString();
    23.             PlayerSavedData.score_coins = coinsCollected;
    24.          //   Debug.Log("coins total on trigger " + PlayerSavedData.score_coins);
    25.             PlayerSavedData.double_score_coins = coinsCollected * 2;
    26.            
    27.         }
    28.     }
    29.     public void singlecoinbuttonclicked()
    30.     {
    31.  
    32.        // Debug.Log("Single coin button is clicked ");
    33.         Debug.Log("coins total on single coin button clicked " + PlayerSavedData.score_coins);
    34.      
    35.         coinstotal.text = PlayerSavedData.score_coins.ToString();
    36.      
    37.     }
    38.     public void doublecoinbuttonclicked()
    39.     {
    40.         coinstotal.text = PlayerSavedData.double_score_coins.ToString();
    41.     }
    42.  
    43. }
    44.  
     
  4. madpwnhammerBit

    madpwnhammerBit

    Joined:
    Jun 2, 2020
    Posts:
    1
    In my case, the problem was in how I update my text. I used "System.Timers.Timer" to update text with intervals, but this approach cause problem with text (it's updated in inspector, but not updated in game). Then I try to move text update in Coroutine and it works fine. I think it's somehow related to multithreading, but I didn't investigate so deep.
     
  5. iQlt

    iQlt

    Joined:
    Oct 14, 2014
    Posts:
    2
    Hello from 2023... Cannot update timer in TextMeshProUGUI text, it just doesn't set the value. Sets only during Scene loads.

    Tried all the solutions from this thread:

    gameObject.SetActive false/true
    ForceMeshUpdate()
    Setting text in Update method
    Setting text via Coroutine
    Setting text via InvokeRepeating
    Disabling Auto Size
    UnityMainThreadDispatcher.Instance().Enqueue(() => _text.SetText(text));

    Already spent 5 hours. How is it possible, that such basic functionality as TextLabel is so buggy in this game engine?

    And it's worth to mention that in Editor everything works fine, the real problems starts when it comes to Android.
     
    Last edited: Aug 13, 2023
  6. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    787
    for me, sometimes the issue was running it from a different thread, but sometimes it was just weird errors which I could only find via attaching the debugger and going step-by-step.
    in an extreme case, I was just destroying the text and creating a new one -- this was near a critical release and we had to move fast. hope this helps somewhat
     
  7. ceciliagabriellecolley

    ceciliagabriellecolley

    Joined:
    Oct 8, 2023
    Posts:
    1
    I encountered the same problem when using Legacy text. I made revisions to a few lines of dialogue in an array of strings, but these changes didn't reflect in the game. I attempted to resolve this by deleting the Legacy Text Game Object and starting over, but the issue remains unresolved. My next step is to copy the code into a new script and see If that will work. I have also gone through everyone else's solutions, but none have worked for me.
     
    xucian likes this.
  8. mimuraunity

    mimuraunity

    Joined:
    Oct 10, 2019
    Posts:
    4
    Thanks for the quick resolution. People like you are the best.
     
    xucian likes this.
  9. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    222

    Wow, the "empty string not updating issue" still lingers in 2023.3.0b1, what a ghost, how does this even acceptable by everyone.....
     
    xucian likes this.
  10. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    787
    I guess it's just priorities.
    I agree bugs like this are too easy not to be fixed (although I didn't look into the actual source code, but it's definitely an small fix), even if they're not tagged as "critical"