2
\$\begingroup\$

I have been working for quite a lot of time with the Unity 2020.3 LTS releases and everything seems to be running smoothly when building for the Android platform. I recently decided to upgrade the Unity version to the latest 2021.3/2022.3 LTS releases to take advantage of some new features, but the same project seems not to behave the same, specifically when building for Android, resulting in stutter/lag.

After some searching, I noticed that a possible culprit could be the vSync count. I was used to setting it to "Every V Blank" in the 2020 versions and below, but apparently the value of vSync is ignored on Unity Android builds from 2021.1 and onwards according to:

The Unity 2021.1 changelog

Android: Removed use of QualitySettings.vSyncCount for Android.

The Unity 2021.1 docs

Mobile platforms ignore QualitySettings.vSyncCount. On mobile devices, when a frame is ready, it displays the next time the screen refreshes. You can use Application.targetFrameRate to control the frame rate on mobile platforms.

This resulted in Unity trying to render everything in the default 30 fps (for Android builds). So, I immediately got into the Unity 2020.3 editor, tried setting the vSync count to "Don't Sync" and added this code:

private void Awake()
{
    Application.targetFrameRate = Screen.currentResolution.refreshRate;
}

which is supposed to cap the framerate to the device's refresh rate, effectively having the same effect as having set the vSync count to "Every V Blank" in the first place. Indeed, it worked like a charm, so I decided to upgrade my project's Unity version to 2022.3. It turned out that it didn't behave the same way as the 2020.3 version did. The same applied for the 2021.3 version. The game seemed to run smoother than not having set Application.targetFrameRate at all, but still there was a lot of stuttering and lag, making the game unplayable.

I later got into profiling the Android builds

This is the 2020 build profiler 2020

This is the 2022 build profiler 2022

Both profiles seem very similar. The only difference I could find is that the average CPU time on the 2020 build was around 8ms, which is indicating a performance of 120fps (as is the refresh rate of the device I am testing on) while on the 2022 build it was around 17ms, indicating 60fps). This didn't make much sense to me, as in both tests I had set the Application.targetFrameRate to Screen.currentResolution.refreshRate. In fact, printing Screen.currentResolution.refreshRate in the Unity 2022 version seemed to output 120. Even in this case though, 60 consistent fps would be good enough and the difference would normally be translated into smoothness and not stuttering/lag. Other than that I couldn't find any other culprit in the profiler.

I also tried setting the Application.targetFrameRate to 60 (as it can generally be considered a good practice for Android builds to reduce battery drain and overheating), but still the same stuttering/lag occurred. I did some further research in how to solve this but I didn't find any solution to this.

As if it wasn't weird enough, I tried making a new Unity 2022 project and imported all the assets the original project has. When building trying out the new project's build in the Unity 2022 version, everything seemed to run smoothly enough. One had to really focus to see the difference between the 2022 and the 2020 version but indeed there was a small, insignificant one. Looking further into this, I tried setting the Application.targetFrameRate to 60 and this is where it got visible. The 2020 version ran at 60 fps really smoothly, but the 2022 version still ran very poorly in terms of stuttering and lag.

Do you have any ideas? Is there anything else I might be missing?

\$\endgroup\$
3
  • \$\begingroup\$ Have you tested this before/after in a build? If it's just in editor, there could be a lot of reasons why different versions would affect performance differently. \$\endgroup\$
    – Wiley Rush
    Commented Jun 17, 2023 at 6:39
  • \$\begingroup\$ I can also see that your two profiler windows have different player names- on one, it is AndroidPlayer, and on the other, it's RedMiM2101K6G. Could the first be running on an emulator and the second on an actual mobile device? \$\endgroup\$
    – Wiley Rush
    Commented Jun 17, 2023 at 6:39
  • \$\begingroup\$ No, both of the profiles are on the same physical Android device after a build. Not sure why it has a different name. On the editor I can't notice any difference between the versions. \$\endgroup\$ Commented Jun 17, 2023 at 8:28

0

You must log in to answer this question.

Browse other questions tagged .