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?