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

Brief flicker of UI with text element when changing position

Discussion in 'UGUI & TextMesh Pro' started by gumboots, Nov 9, 2018.

  1. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi there,

    I am moving a UI element's position by modifying its RectTransform.padding.left value. I first set the left value to the full value (to calculate its entire width), and then I set left to 0 to animate it back to the full value.

    However I see a very brief flicker of it at its full value before it returns to 0, and forcing a canvas update doesn't seem to fix it. Here is the code I'm using:

    Code (CSharp):
    1. void OnUpdated() {
    2.     HorizontalLayoutGroup.padding.left = 40;
    3.  
    4.     Description.ForceMeshUpdate(true);
    5.     Progress.ForceMeshUpdate(true);
    6.  
    7.     Canvas.ForceUpdateCanvases();
    8.  
    9.     _width = Mathf.CeilToInt(RectTransform.rect.width);
    10.  
    11.     HorizontalLayoutGroup.padding.left = 0;
    12.  
    13.     Description.ForceMeshUpdate(true);
    14.     Progress.ForceMeshUpdate(true);
    15.     Canvas.ForceUpdateCanvases();
    16.    
    17.     Tween();
    18. }
    (The value isn't always 40, hence needing to calculate the width. I just put 40 there to make it more easily understandable.)

    Is there a way other than ForceUpdateCanvases to make a UI element update complete so I don't see its old position?