Search Unity

TextMesh Pro Why does adding TextMeshProUGUI component with code change the RectTransform size and rotation

Discussion in 'UGUI & TextMesh Pro' started by hellomercury, Dec 9, 2020.

  1. hellomercury

    hellomercury

    Joined:
    Nov 9, 2017
    Posts:
    2
    When I use the following code to add a TextMeshProUGUI component at runtime, the size of the GameObject to which the component is added has changed. it looks like a default value.

    Code (CSharp):
    1. TextMeshProUGUI text = InBindGameObj.AddComponent<TextMeshProUGUI>();
    I tried to create an empty object in the scene and then add the Text component, the size of the component will also be changed to the default size

    Why not set the size according to the bound GameObject like text,Or what setting can I use to achieve the same effect as text?


    And when can I use TextMesh Pro with Addressables? Now I can only dynamically add TextMeshProUGUI to use it with Addressables. If there are other implementation methods, please provide me with some reference, thank you very much
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The size of the RectTransform should be based on the default settings defined in the TMP Settings.

    upload_2020-12-9_11-59-15.png

    Do you have an example / sample scene / project that you could provide of show you are trying to use Addressables with TMP? I could certainly take a look and provide feedback thereafter.
     
  3. hellomercury

    hellomercury

    Joined:
    Nov 9, 2017
    Posts:
    2
    Thanks Reply

    I checked the 'Auto Size Text Container' option, but this option is adaptive to the size of the text currently entered, but I want the size of the TMP component to be the same as the bound GameObject, because I want to enter content dynamically


    version 2.0.1

    prefab


    When I use Addressables and TMP together, if I add the Resources folder under TMP to Addressables, TMP will not be displayed. If I do not add the Resources folder under TMP to Addressables, there will be a font file in the UI resource pack, and there will be a copy in Resources under TMP.


    So I tried to delete the TMP component in the prefabs and add the TMP component in the run. Encountered the above problem