docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class LayoutRebuilder

    Wrapper class for managing layout rebuilding of CanvasElement.

    Inheritance
    object
    LayoutRebuilder
    Implements
    ICanvasElement
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.UI
    Assembly: UnityEngine.UI.dll
    Syntax
    public class LayoutRebuilder : ICanvasElement

    Properties

    transform

    The Transform this LayoutRebuilder is targeting for rebuild.

    Declaration
    public Transform transform { get; }
    Property Value
    Type Description
    Transform

    Methods

    Equals(object)

    Does the passed rebuilder point to the same CanvasElement.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The other object to compare

    Returns
    Type Description
    bool

    Are they equal

    Overrides
    object.Equals(object)

    ForceRebuildLayoutImmediate(RectTransform)

    Forces an immediate rebuild of the layout element and child layout elements affected by the calculations.

    Declaration
    public static void ForceRebuildLayoutImmediate(RectTransform layoutRoot)
    Parameters
    Type Name Description
    RectTransform layoutRoot

    The layout element to perform the layout rebuild on.

    Remarks

    Normal use of the layout system should not use this method. Instead MarkLayoutForRebuild should be used instead, which triggers a delayed layout rebuild during the next layout pass. The delayed rebuild automatically handles objects in the entire layout hierarchy in the correct order, and prevents multiple recalculations for the same layout elements. However, for special layout calculation needs, ::ref::ForceRebuildLayoutImmediate can be used to get the layout of a sub-tree resolved immediately. This can even be done from inside layout calculation methods such as ILayoutController.SetLayoutHorizontal orILayoutController.SetLayoutVertical. Usage should be restricted to cases where multiple layout passes are unavaoidable despite the extra cost in performance.

    GetHashCode()

    Returns the instance ID of the target transform as a hash code.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    The instance ID of the target transform.

    Overrides
    object.GetHashCode()

    GraphicUpdateComplete()

    Called when the graphic update is complete.

    Declaration
    public void GraphicUpdateComplete()

    IsDestroyed()

    Has the native representation of this LayoutRebuilder been destroyed?

    Declaration
    public bool IsDestroyed()
    Returns
    Type Description
    bool

    True if the target transform has been destroyed.

    IsLayoutRebuildPending(Transform)

    Checks whether a layout rebuild is queued for an element.

    Declaration
    public static bool IsLayoutRebuildPending(Transform transform)
    Parameters
    Type Name Description
    Transform transform

    The element to query.

    Returns
    Type Description
    bool

    True if a layout rebuild is queued for the element's layout root, otherwise false.

    Remarks

    Unity resolves the element to the layout root that owns its rebuild, so a child of a layout group reports true whenever an ancestor layout is queued. An element that takes part in no layout always reports false. A false result doesn't mean the geometry is final, because a script can mark the element dirty again later in the same frame.

    Examples
    using UnityEngine;
    using UnityEngine.UI; // Required when using UI elements.
    
    public class TooltipPositionerExample : MonoBehaviour
    {
        public RectTransform tooltip;
    
        // Places the tooltip above its target, once the tooltip's own layout has settled.
        public void PositionAbove(RectTransform target)
        {
            // A queued rebuild means the tooltip size is not final, so wait for a later frame.
            if (LayoutRebuilder.IsLayoutRebuildPending(tooltip))
                return;
    
            float offset = (tooltip.rect.height + target.rect.height) * 0.5f;
            tooltip.position = target.position + new Vector3(0f, offset, 0f);
        }
    }

    LayoutComplete()

    Called when the layout rebuild is complete. Returns this instance to the rebuilder pool.

    Declaration
    public void LayoutComplete()

    MarkLayoutForRebuild(RectTransform)

    Mark the given RectTransform as needing it's layout to be recalculated during the next layout pass.

    Declaration
    public static void MarkLayoutForRebuild(RectTransform rect)
    Parameters
    Type Name Description
    RectTransform rect

    Rect to rebuild.

    Rebuild(CanvasUpdate)

    Rebuilds the layout during the CanvasUpdate.Layout update stage.

    Declaration
    public void Rebuild(CanvasUpdate executing)
    Parameters
    Type Name Description
    CanvasUpdate executing

    The canvas update stage currently being executed.

    ToString()

    Returns a descriptive string showing the target transform's name.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string describing this LayoutRebuilder.

    Overrides
    object.ToString()

    Implements

    ICanvasElement
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)