TextMeshProGUI not updating text

Hello i was trying to find this on google but i failed.

  1. I have 2 fields in my GUI one is refreshing normally after ForceMeshUpdate(), other refresh only when object is destroyed and recreated again, but i need update it just after button click , can you please help?

Thanks

a) With this code text update correctly.

     var clusterText =    selectedCluster.GetComponent<TextMeshProUGUI>();
                             clusterText.text = clusterNumber.ToString();
                             clusterText.ForceMeshUpdate();

b) Here it is not working

   if (item.name == "TotalObjects")
                    {
                        foreach (Transform item2 in item.transform)
                        {
                            if (item2.name == "TotalObjectsGO")
                            {

                                var itemText = item2.GetComponent<TextMeshProUGUI>();
                                itemText.text = Galaxy.GetClusterObject(clusterNumber).objectCount.ToString();
                                itemText.ForceMeshUpdate();
                             

                            }
                        }
                    }

Only difference in those 2 are that first “selectedCluster” is GameObjcet and “item2” is a Transform but i also tried this and still no work.

    var itemText = item2.gameObject.GetComponent<TextMeshProUGUI>();
                                itemText.text = Galaxy.GetClusterObject(clusterNumber).objectCount.ToString();
                                itemText.ForceMeshUpdate();

Why are you doing ForceMeshUpdate? Did you verify that the text wasn’t updated and just simply not to large for the textmeshprougui object to display? Setting the text property of the component should be enough to update it.

Ye i did , without ForceMeshUpdate it wont update in first example. Text is fine if i destroy and create object again there is correct text displayed,There must be some problem because in second example i am trying to updayt text of grandchild but i was unable to fix it.

Anytime i click on planet or button in botom of screen i want text to update but only top text is updated and no bottom table

7091293--844534--asdasd.jpg

ForceMeshUpdate should not be required. Something seems off. Can you show me your textMeshProUGUI object with your hierarchy?

1 Like

You mean like this?

7091608--844564--screen.png

Ok, so this is part of a prefab. Is it properly under a canvas in your scene? The object seems fine from what I can see in that screenshot.

As I mentioned, this is not normal behavior. You shouldn’t have to call ForceMeshUpdate or destroy the text and recreate it. I need to see a bit more code of your second script. Can you just post the whole script or is it super long?

@Brathnann you was right this statement is enough for text update.I found bug in my static class.I correctly changed number but i didnt call for object to change according that number, thats why it was working after recreating because in method for recreate i call that change.

var clusterObject = Galaxy.GetClusterObject(clusterNumber);
totalObjectsGO.GetComponent<TextMeshProUGUI>().text= clusterObject.objectCount.ToString();
public static void LoadPlanetsInCluster(int clusterToLoad)
        {

            foreach (ClusterObject item in loadedClusterObjectsList)
            {
                if (item.clusterNumber == clusterToLoad)
                {
                    loadedPlanetObjectsList = item.planetList;
                    loadedClusterObject = item;
                }
             
            }
       
            galaxyLoaded = true;

        }
1 Like

Nice! Glad you got it figured out.