Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Aspect Ratio Fitter performance issue

Discussion in 'UGUI & TextMesh Pro' started by Gamba, Mar 2, 2015.

  1. Gamba

    Gamba

    Joined:
    Feb 8, 2015
    Posts:
    29
    I've found frame hit in a game I'm currently working on and it seems to be caused by the Aspect Ratio Fitter. Before I submit a bug report, I wanted to ping the community here and see if anyone else has experienced a similar issue or if I'm just doing something wrong.

    The game I'm on, has it's design heavily dependent on the width of the screen, and for that reason, we've forced the camera to 16:9 so that it will play the same across 3:2, 4:3, and 16:9 iOS devices. Since we're using uGUI, I thought that adding the Aspect Ratio Fitter (http://docs.unity3d.com/Manual/script-AspectRatioFitter.html, http://docs.unity3d.com/462/Documentation/ScriptReference/UI.AspectRatioFitter.html) as a component on the canvas object would work out well as a no hassle way to fit the UI to this aspect as well.

    However, I notice a ~20 fps drop from 115, down to 95, when the aspect mode of this component is set to "width controls height" or "height controls width" ("fit in parent" and envelope parent" incur even higher costs). In the profiler, AspectRatioFitter.OnRectTransformDimensionsChange() appears to be called every frame as if the Fitter is re-sizing all screen assets over and over again. Now, I am getting 30 fps on device which is our target, but the game is still in early development and includes a lot of low quality environments as placeholder. As the game grows, I don't want this problem to bite me later.

    It seems to me that there should be a single call if the aspect ratio is changed, outside of that, nothing else should be happening quite so often, especially on mobile where there are fixed screen sizes.

    Any information anyone can provide to shed light on this would be greatly appreciated.

    Cheers!
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Ok, looked through the public source and there does not seem to be any good reason why that would be happening.
    The OnRectTransformDimensionsChange should only be called if the actual displayed dimensions change, this event is fired from monoBehaviour. The reason the fit and envelop methods do more is because they do more in code :D The other modes just set size by anchors.

    So from the looks of it, it looks like an engine issue and should be logged as a bug.
    Unity is calling OnRectTransformDimensionsChange when in fact is shouldn't, likely to be a player issue so also mention the platfrom
     
  3. Gamba

    Gamba

    Joined:
    Feb 8, 2015
    Posts:
    29
    Thanks a lot for the extra information Simon.

    I've isolated the issue in a smaller project and submitted it as a bug in the player. Hopefully it is something that can be resolved easily.
     
    SimonDarksideJ likes this.
  4. Gamba

    Gamba

    Joined:
    Feb 8, 2015
    Posts:
    29
    Just an Update.

    I never received any information or response from Unity on this, but my coworker found that having a Canvas Scaler and the Aspect Ratio Fitter on the same game object was what was causing the problem. When we made a blank child object and put the aspect ratio fitter on that and then moved the rest of the UI to be a child of that object, we were able to get the desired behavior, without the processor overhead of endless RectTransform resizing.

    Hope that can help someone else.
     
    Novack likes this.