Hello, I am developing an Android game where I have the target frame rate set to 120 FPS, via this line of code:
Application.targetFrameRate = 120;
I used to have this line of code in the “Start()” function of a script I had attached to the “Main Camera”. This worked for a while, until I noticed that the game would randomly start at 30FPS when building and running it on my mobile device (Samsung Galaxy S22 Ultra). It would not change, it would stay at 30FPS. If I closed down Unity, re-opened it, and rebuilt it, it usually fixed the problem and I would get 120 FPS again on the mobile device.
I later moved the line of code to my GameManager script under “Start”, but again I notice I randomly get 30FPS, basically same problem as before.
Do you know what the problem might be? Do I need to wait for something to initialize first before setting this setting? I read through the documentation and there is no mention of anything around that. Any help or advice is greatly appreciated, thanks!
Is the target frame rate being set anywhere else? I’d do a “Find All References” in your IDE to find out, but note that this might not find it in any 3rd party code you’ve got. It could be that it’s getting set by more than one script, and the execution order is changing between builds.
The other thing I’d check is whether or not your game is running fast enough to update at 120hz, particularly with whatever vsync settings you may have enabled. It could be that something in your game slows it down, such as an expensive effect which is only on the screen sometimes. I expect that you’d have noticed that, but it’s worth asking just in case.
Thanks for the response. This is a brand new project that I started just a couple days ago. I have not touched vsync. I only reference the frame rate in that one spot and that is it. It is not referenced anywhere else in the project. The entire project is all of my own code, with the exception of a joystick pack for movement. Its a 2d top down pixel style game, very simple with not much going on.
If I comment out the line “Application.targetFrameRate = 120;” then on my cheap laptop it runs over 200 FPS, and runs exactly 30FPS on my mobile device. 30FPS is the default target FPS for any mobile device.
I can tell its in the “glitched” mode because it starts at exactly 30 FPS, and stays exactly 30FPS no matter what I do. It doesn’t fluctuate or anything.
When Application.targetFrameRate is not set then application has Vsync off.
If you set this value it will try to reach target frame rate, however it’s not guaranteed. Vsync can be ignored or overridden by hardware or system and it looks like your device imposes 30 fps cap.
Maybe device was short on resources (battery? memory?) because some other applications running in background ate it, so operating system capped framerate? If that is not the case I would consider this as bug.