Search Unity

TextMesh Pro - RectTransform changing size at Runtime

Discussion in 'UGUI & TextMesh Pro' started by bjrafeld, Aug 11, 2017.

  1. bjrafeld

    bjrafeld

    Joined:
    Apr 19, 2016
    Posts:
    4
    I've recently shifted to using TextMesh Pro in my Unity project, but am running into issues with the RectTransform of my TextMeshProUGUI object being modified at runtime. I have the anchors of this object set to match the boundaries of the canvas with the Rect positioned inside of that. When I run the scene, however, the Rect boundaries change and expand outside of the canvas boundaries.

    I have a Canvas Scaler attached to the Canvas object only and none of the children have additional Scaler components so I don't think that's the issue. The TextMeshPro component seems to be the culprit since removing it completely from that object (just disabling it doesn't fix the issue) keeps the Rect in place. Any suggestions on how to keep my RectTransform from misbehaving?

    Thanks!
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The RectTransform of the text object should not be changing unless you are using some layout components like a ContentSizeFitter or similar components as those would affect the RectTransform of the text object.

    Are you using any layout components on the parents or on the text object itself?
     
  3. bjrafeld

    bjrafeld

    Joined:
    Apr 19, 2016
    Posts:
    4
    No Layout components on anything in that hierarchy.

    Something else to note: this does NOT happen when I start the scene and that particular text component is Enabled. This only occurs when the scene starts with that object (or one of its parents) disabled.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide me with the steps to re-create a scene setup that would reproduce the behavior?

    Please include an image of the repro scene hierarchy and each of the objects so I can see their transform and component settings.
     
  5. bjrafeld

    bjrafeld

    Joined:
    Apr 19, 2016
    Posts:
    4
    Figured out the problem - I was clearing the text present on that component when the scene starts (by setting it to null). This was causing the RectTransform to resize. Clearing the text by setting that text to an empty string fixes the issue.

    Is assigning a null string to that text field bad practice or known to cause this kind of behavior?
     
    DigiBotStudios likes this.
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Changing the content of the text should not cause the RectTransform of the text to change unless some Layout component which pays attention to content size is used somewhere in the hierarchy of the text object.

    In terms of the practice of setting the text to null that is fine although I am curious as to why you are clearing the text?
     
  7. bjrafeld

    bjrafeld

    Joined:
    Apr 19, 2016
    Posts:
    4
    The contents of the text on that component were placeholder as it's being cleared out and changed frequently while the game is running.