Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Brief flicker of UI with text element when changing position

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

  1. gumboots


    May 24, 2011
    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;
    4.     Description.ForceMeshUpdate(true);
    5.     Progress.ForceMeshUpdate(true);
    7.     Canvas.ForceUpdateCanvases();
    9.     _width = Mathf.CeilToInt(RectTransform.rect.width);
    11.     HorizontalLayoutGroup.padding.left = 0;
    13.     Description.ForceMeshUpdate(true);
    14.     Progress.ForceMeshUpdate(true);
    15.     Canvas.ForceUpdateCanvases();
    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?