Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Why doesn't the TextMeshPro textBounds get updated between frames in Play Mode Unit tests?

Discussion in 'Editor & General Support' started by highpockets, Aug 31, 2022.

  1. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    67
    Hello,

    I have a need to change the text of a text mesh pro UI text object and retrieve its textBounds to resize an object for a unit test. I have included Unity.TextMeshPro in the .asmdef file. I have tried multiple things like waiting for multiple frames, calling ForceMeshUpdate(), and even calling Canvas.ForceUpdateCanvases(), but the returned textBounds is always Center: (0.00, 0.00, 0.00), Extents: (-2147484000.00, -2147484000.00, 0.00). However, the text itself shows that it has changed to the correct string.

    While doing the same thing in regular play mode, I just have to wait a frame after changing the text to get the correct textBounds. Is there something I'm missing to make this work in a Unity Play Mode Unit Test?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    The source code should reveal this. Check out the source code over in the Packages directory to see if there are other ways of accessing the bounds recalc. I assume they just made it lazy so they don't waste time changing bounds many times per frame, such as if several scripts all update a field.

    ALSO... is this really providing you value to write a test around???
     
  3. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    67
    Last edited: Aug 31, 2022