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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get the size of a rectTransform with ContentSizeFilter Attached

Discussion in 'UGUI & TextMesh Pro' started by gray_schofield, Nov 13, 2015.

  1. gray_schofield

    gray_schofield

    Joined:
    Feb 19, 2014
    Posts:
    6

    I am currently messing up with some customized text view stuff. As the above picture indicates, i added a content size filter to the text, so that it would resize with it's content, this works fine.
    But now in my code, i want to access its derived height, i.e the grayed number 30.6...
    normally with a RectTransform , i just need to use .rect.height to get its height, but as in
    this case, it always return 0. Does anyone know how to get the height in this case
     
  2. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    As far as I was aware .rect.height should give the proper height, maybe you have to wait a frame for it to be set or something depending on when/where you're looking at .rect.height.
     
    gray_schofield likes this.
  3. gray_schofield

    gray_schofield

    Joined:
    Feb 19, 2014
    Posts:
    6
    Thanks DWilliams
    Indeed, I have to wait for the end of the frame in order to get the height