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

Font size of Prefab'd Text UIs different than was Set

Discussion in 'UGUI & TextMesh Pro' started by infinitypbr, Oct 18, 2014.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    Hello,

    I set a single line of text to be the correct size. Its on a canvas with a Reference Resolution so it should be the same on all screen resolutions.

    However, when I instantiate the prefab of the text UI object, and parent it under the canvas, the font size is completely different. Originally I had it at size 100, but had to lower it to 20 to make it the right size on the screen.

    Now using it on the iPhone 5s, the font size seems to be 1/2 of what it should be. I'm guessing it has something to do with the resolution of the display when it's instantiated.

    Is there a way to instantiate the text UI object without having this issue? I'd like it to work the way I had it set up, using the Reference Resolution of the parent canvas to keep it the right size on all screen resolutions.

    Thanks!
     
  2. bgs

    bgs

    Joined:
    Jan 14, 2014
    Posts:
    12
    Hey, I've been able to temporarily fix it by changing the scale to 1 after instantiating
    Code (CSharp):
    1. instantiatedGo.transform.localScale = Vector3.one;
    I'm not sure if this behaviour is a bug or actually intended. Perhaps the scaling of the elements within the prefab gets saved from the canvas and then affected once again by the reference resolution when instantiated.
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I had not seen that -- I didn't know there was a FAQ :/ Scale works, but I'll check out SetParent instead.
     
  5. bgs

    bgs

    Joined:
    Jan 14, 2014
    Posts:
    12
    Hey runevision, it does occur when using SetParent. Here is a repro project attached. Let me know if I should submit it as a bug.
     

    Attached Files:

  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    No need to submit this as a bug.

    the forum FAQ said to set the second parameter of the SetParent method to false. The page I linked to say that too. Do you have any ideas how we can make it more clear? Maybe we should not make the second parameter be optional?
     
  7. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    For me, I never knew there was a SetParent() function. I'll use it now. However, what I'd really like is a WorldsToCanvasPoint function -- that'd be helpful :D
     
  8. bgs

    bgs

    Joined:
    Jan 14, 2014
    Posts:
    12
    Thank you for this clarification. I apologize for not looking through the forum FAQ and skimming the linked how-to, I feel stupid. I believe it is clear enough!

    Also, I understand why worldPosStays param defaults to true, since that is what you would want in a non UI scenario most of the time.

    Thanks again!