AspectRatioFitter new restriction in 2020.2

Hi! What the point of this restriction now? I can’t see any reason for that and we used that more than year without issues. We used ARF in 2020.1 without problem on ScreenSpace - Overlay parent canvas (and have nested canvases for reducing canvas rebuild cost), but now it completely breaks our UI because fitter disabled and our UI now has wrong sizes

@Stephan_B I know you’re most responsible for TMP, but I can see only you answer the questions in this forum. (in addition @phil-Unity )

6624277--754816--upload_2020-12-15_19-43-44.png

As temp fix (because we need deliver build for investors today) we copied com.unity.ugui into the project and commented out that restriction.

3 Likes

Just some quick findings:

The issue appears to be present only when you instantiate a prefab dynamically. The aspect ratio fitter will update only when you resize the screen so that it affects the ARF in some way.

You could hack it by calling its private methods with SendMessage.

var go = Instantiate(prefab, target, false);
var fitter = go.GetComponent<AspectRatioFitter>();
fitter.SendMessage("SetDirty");

You could also create a new class:

public class SuperAspectRatioFitter : AspectRatioFitter
{
    protected override void Start()
    {
        base.Start();
        SetDirty();
    }
}

Apart from that looks like a bug.

1 Like

It’s not relative to resize etc. (which in your case can be another thing, possible bug, which on resize spawned UI from prefab get wrong renderMode property value).
About what I posted is - if your root canvas render mode not WorldSpace internal check in editor will get false from IsComponentValidOnObject and will show a warning in the editor and will prevent ASF from doing anything at runtime.
6625120--755038--upload_2020-12-15_23-49-43.png

I thought this was a bug! I really dont like this restriction, as it forces me to not upgrade to 2020.2 or to change the logic of my ui… is there a simpler workaround?

Workaround already mentioned in my OP.

@Stephan_B @phil-Unity sorry but ping you again.

I do not believe it.

Several of my backgrounds no longer appeared in the final build, I finally found the cause. I hope a fix will come out soon!

1 Like

I find another bug…
In 2020.2,they add a new variable:

//Does the gameobject has a parent for reference to enable FitToParent/EnvelopeParent modes.
        private bool m_DoesParentExist = false;

This variable is false in default,and will update in OnEnable() after SetDirty().SetDirty() will adjust recttransform.But if your AspectMode is FitInParent or EnvelopeParent,it will check if m_DoesParentExist is true.So finally,if you use AspectMode.FitInParent or AspectMode.EnvelopeParent,and build a release package,you will find image disappear or in a wrong position…(Maybe because of [ExecuteAlways] attribute,it performs perfect in editor play)
My english is not good,hope you can understand:)

1 Like

I managed to get it to work by copying AspectRatioFitterEditor.cs and AspectRatioFitter.cs from 2020.1 to 2020.2
found in
C:\Program Files\Unity\Hub\Editor\2020.1.12f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\Layout,
and
C:\Program Files\Unity\Hub\Editor\2020.1.12f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Editor\UI

4 Likes

Any comments from Unity? I see you guys answer other threads but ignoring this one :frowning: @Stephan_B @phil-Unity sorry but ping you again.

Bump

I just switched to 2020.2 and found this christmas gift from the unity team. I’m going to try to copy the files as suggested, but this is getting stupid. Unfortunately this seems like the intended behaviour, so I doubt they pay any attention to a bug report (I’d still vote for it, though).
Obviously they don’t want us to do it this way, but they should come up with a solution and put it in the warnning instead of just ruining everyone’s work. I don’t want to be manually changing this every time I update the engine, so instead they should fix whatever problem may happen behind the scenes, to just allow it.
I deeply regret how everytime, stupid things like visual scripting that are just to attract noobs get lots of resources while this key elements that are fundamental but where never finished like the GUI get so little atention.

@Joachim_Ante_1 deeply sorry for ping you, but we are completely ignored by the Unity UI staff and I don’t know whom to ask about that. Release notes contain no information about the reason for that and have only 2 fixes in irrelevant bugs.

:frowning:

Can you submit a bug report with project and steps to reproduce this issue (if you have not already done so)? Although I focus on text related issues, I’ll take a look and discuss with Phil once he is back from the Holidays.

Thanks! Yeah, I know you TMP responsible, I mentioned that in start post :slight_smile: @Stephan_B
Submitted:
Case 1302464
In addition example of how it works in 2020.1 as expected and if you’ll scale that to widescreen monitors red square will be in the correct position (with all other UI parts in our project) and wouldn’t stretch. Also, it will scale properly for all screens (Imagine this red square like RTS game minimap).


And now in 2020.2 with this new Aspect Ration Fitter restriction mentioned (and even pointed in code) in start post (and you can see the warning in ARF ):


Pretty sure I ran into this one too, my workaround was to call

var fitter = this.background.GetComponent<AspectRatioFitter>();
fitter.enabled = false;
fitter.enabled = true;

As I already pointed a couple of times - it wouldn’t work with canvases other than WorldSpace. Read carefully :slight_smile:
In 2020.2 they added new rule - IsComponentValidOnObject method. Your enable true\false will trigger OnEnable which will call SetDirty method which in turn will run this
6671218--763777--upload_2020-12-30_14-37-35.png
And in IsComponentValidOnObject in 2020.2 you can see this condition which will return you false
6671218--763780--upload_2020-12-30_14-38-2.png
and condition above will be valid and it will just return you from UpdateRect without any work.
In 2020.1 you wouldn’t see this condition and nested canvases with parent ScreenSpace - Overlay canvas will work as expected with correct resizing.
6671218--763774--upload_2020-12-30_14-37-16.png

6671218--763765--upload_2020-12-30_14-32-19.png
6671218--763771--upload_2020-12-30_14-34-11.png

2 Likes

Interesting… my canvas is screen space and my workaround seems to work for my 2D-only game. Also, there are no editor warnings. I haven’t dug into the Unity source but this may well be two bugs, like @NiLiu suggested. In any case, thanks for filing a bug.

You didn’t see it because you not on 2020.2 I suppose?