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

Help in triggering Layout Rebuild is needed

Discussion in 'UGUI & TextMesh Pro' started by dot_entity, Mar 5, 2015.

  1. dot_entity

    dot_entity

    Joined:
    Nov 2, 2012
    Posts:
    79
    Hello community!

    Copied from the manual's documentation on recalculating the Auto Layout of the UI system, by using the LayoutRebuilder.MarkLayoutForRebuild (transform as RectTransform) function:

    "The rebuild will not happen immediately, but at the end of the current frame, just before rendering happens."​

    From this instruction itself (and I believe I verified it with some testing), I assume that I have to wait for the next frame, so that the current modifications in the layout's properties will take effect and therefore to be possible to consider them in new calculations. With this assumption I have been using a yield instruction right after I have called the Rebuild function. Am I correct so far?

    There is a visual side effect of using the yield coroutine, however. Given that the layout changes are applied within a number of frames by the end of each one the graphics are also calculated, the result is an animation effect of the changes. Although in my case it is not a bad contribution (rather the opposite), I was wondering on one hand, if I even approach the whole thing correctly and, on the other, what can be done if this animation effect is not desired. Is there even a way to move to the next frame, without having the graphics of the particular objects updated, until we want this to happen (in this case, after the layout changes have been applied)?

    Thanks in advance for any help. Since the UI system is relatively new there are not many examples around (especially regarding run time GUI development) from which I can get ideas and solutions.
     
  2. DaveCrowdStar

    DaveCrowdStar

    Joined:
    Nov 13, 2015
    Posts:
    13
    I am having trouble triggering a rebuild on an asset which is not instantiated yet. I would like to know the size of it so I can make virtual rects. My scroll contains thousands of elements, and I don't want thousands of instances. So I need the size