1

I have a ui panel with an AnimatorController. The panel contains an image with an AspectRatioFitter component (the one that comes with the unity ui system). The aspect ratio fitter is set to "Fit In Parent" and therefor have one public float variable called "Aspect Ratio" to control the aspect.

The animator controller start an animation that change the value "Aspect Ratio" over time.

The problem is that the size of the rect transform does not update accordingly to the new aspect ratio. Not during the animation, nor when the animation finishes. It never applies the new value.

I can see it work, if I for example change the value manually, or if I disable and then enable the AspectRatioFitter component manually.

For testing purposes I have tried calling the following on the GameObject in an Update() method. But it will not update the aspect:

LayoutRebuilder.MarkLayoutForRebuild(this.transform as RectTransform);
LayoutRebuilder.ForceRebuildLayoutImmediate(this.transform as RectTransform);
Canvas.ForceUpdateCanvases();
this.GetComponent<Image>().SetAllDirty();
this.GetComponent<Image>().SetLayoutDirty();
this.GetComponent<Image>().Rebuild(CanvasUpdate.LatePreRender);
this.GetComponent<Image>().Rebuild(CanvasUpdate.Layout);
this.GetComponent<Image>().Rebuild(CanvasUpdate.MaxUpdateValue);
this.GetComponent<Image>().Rebuild(CanvasUpdate.PostLayout);
this.GetComponent<Image>().Rebuild(CanvasUpdate.Prelayout);
this.GetComponent<Image>().Rebuild(CanvasUpdate.PreRender);

So why is the layout not updated? And how can I solve this?

jake
  • 73
  • 1
  • 2
  • 6
  • So no one have solution to this one? My solution so far is a script that simply disable and enable the AspectRatioFitter in the Update() method... great unity – jake Nov 17 '15 at 08:36
  • Sounds like a bug, most UI components are meant to be animatable. So I'd log it using he Unity bug reporter in the editor and see what comes back. If you want to do the Disable/Enable method (when it is changed!) then do it in late update as the UI will have finished being updated back the backend then. In Update it is still being manipulated) – Darkside Jan 18 '16 at 12:25

0 Answers0