Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Brief flicker of UI with text element when changing position

Discussion in 'Unity UI & TextMesh Pro' started by gumboots, Nov 9, 2018 at 5:35 AM.

  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?