Search Unity

text.preferredHeight bug?

Discussion in 'UGUI & TextMesh Pro' started by pixpusher2, Aug 29, 2014.

  1. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Hi, I'm having issue with Text's preferredHeight giving the wrong result when I mouse over the button for the first time. It corrects itself when I move away and mouse over again.

    I've tried a few different fonts with the same result, so it's not a font problem. Anyone having similar issue?

    I've extracted the menu from my project into a stand alone scene to show the issue. Attached is a screenshot and the Project file if anyone wants to give it a test. Thanks

    To recreate the issue:
    1) mouse over any of the buttons
    2) move away and mouse over the button again
    You'll notice that the text box is longer on the first mouse over

    preferredheightbug.jpg
     

    Attached Files:

  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Hi. If you believe you've found a bug, please file a bug report with the project attached and a description of how to reproduce the problem.
     
  3. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Thanks. Reported (Case 629734)
     
  4. Panzerhandschuh

    Panzerhandschuh

    Joined:
    Dec 4, 2012
    Posts:
    17
    I was having this problem too. For some reason the text box needs to be larger than the text to properly calculate the preferred height. As a temporary fix, you can make the initial size of the text box much larger than it will ever need to be.
     
    pixpusher2 likes this.
  5. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Thanks, that does help!
    However because my project have text of various length, the bug still pops up whenever I mouse over a shorter text before going over to a longer one. Perhaps I could temporary hack it to reset to a larger text box before attempting to calculate the preferred height again.
     
  6. Panzerhandschuh

    Panzerhandschuh

    Joined:
    Dec 4, 2012
    Posts:
    17
    Making the text box size larger right before finding the preferredHeight should fix the problem, but it's kinda dumb that it's even necessary to do. Hopefully this bug gets fixed.
     
    pixpusher2 likes this.