Search Unity

Textmesh Pro Adjust Yellow Rectangle Alignment Relative to Transform

Discussion in 'UGUI & TextMesh Pro' started by starfoxy, Mar 8, 2021.

  1. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I have what is likely a super basic question but after scouring docs and videos, I am no closer to an answer. I will list my steps here:

    1. Create 3D Object > Text - TextMeshPro
    2. Notice that the TextmeshPro object is huge.
    3. Adjust the font size, alignment, etc.
    4. Notice that the yellow container rect is still huge and text is small.
    5. Try adjusting the yellow container rect by sizing it down.
    6. Notice that the yellow container rect no longer is at 0,0,0 on the transform.
    7. Seeing no way of adjusting this, ask the fine unity forum denizens what can be done.

    So I realize this is really kind of cosmetic but it drives me bonkers. How can I have my yellow text container rectangle align center, center to my transform?
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The yellow rectangle represents the margins of the text. These margins allow a user to offset the position of the text relative to the RectTransform.

    Margins can be adjusted by using the Margin controls (white squares) and RectTransform by using the widget that shows up in the middle of line segments as seen below.

    upload_2021-3-8_15-46-35.png

    The Margin values are also visible in the Extra Settings of the text object inspector as seen below.

    upload_2021-3-8_15-47-58.png

    Setting the margin values in the text inspector back to zero will reset / re-align everything with the RectTransform.
     
  3. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Thank you for your help but I may not have been clear as to what I would like to achieve. I have attached a new image here to demonstrate. Why is the text object transform not centered with the text object itself? How may I address this?
     

    Attached Files:

  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you post an image of the RectTransform values?

    I suspect the Pivot of the RectTransform is not located at the center of the RectTransform which would be (0.5, 0.5). Perhaps you moved the RectTransform's pivot by inadvertently.

    upload_2021-3-9_22-54-24.png
     
    Last edited: Mar 10, 2021
  5. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Great idea. I have tried this and while it's *better* on the X axis, Y is still off. I have attached an updated screenshot.

    I also set the x and y pivot values to 0,0 but not sure if I should be messing with those at all. It did help a bit when making pivot center and 0,0 X,Y pivot values.
     

    Attached Files:

    Last edited: Mar 10, 2021