Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity UI At what time are CanvasScaler.scaleFactor and RectTransform.SetInsetAndSizeFromParentEdge() applied?

Discussion in 'UGUI & TextMesh Pro' started by Nananaaa, Apr 7, 2019.

  1. Nananaaa

    Nananaaa

    Joined:
    Jul 24, 2016
    Posts:
    31
    Please consider the following code:

    Code (CSharp):
    1. someCanvasScaler.scaleFactor = 1.234f;
    2. someRectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 100, parentRectTransform.rect.height - 100);
    Is it technically possible, that scaleFactor is applied AFTER SetInsetAndSizeFromParentEdge()?
    If so, can you please briefly explain why?

    Some more background information:
    The code snippet is used at a slider that enables the user to scale the size of the user-interface. After scaling the UI, some panels need to be repositioned to prevent them from overlapping. It's basically working, except that someRectTransform sometimes overlaps another panel, which indicates that the scaleFactor is applied after SetInsetAndSizeFromParentEdge. Deferring the call of SetInsetAndSizeFromParentEdge() by one frame fixes the issue, but also causes a little (unwanted) flickering. Now I'd like to understand what's going on, to be able to implement it properly.

    Any clarifications are welcome,
    Thank you,
    Michael.