- Home /
Fast frame rate drops
Hey! I have programmed a game for Android. The frame rate drops from 60 to 30 really quickly and back up again, resulting in a lagging game. I have set Application.targetFrameRate = 60;
but that still doesn't work. Sometimes I have a constant 60 but only for a few seconds and then it starts dropping again. Any ideas? Maybe any certain commands or stuff in my scripts which could cause it?
nope. a finish 3d game. Not using any complex 3d models though
$$anonymous$$aybe you can turn down your fixed Timespet if it is not already done
(Ofc it will make your game lower with physic calculations)
Answer by Tobychappell · Jul 08, 2018 at 10:34 AM
For loops dont necessarily slow the game down, its what happening inside them that does. Try commenting out all the code in the for loop and see the performance difference.
Dont take stabs in the dark regarding performance issues.
Use the Profiler and see what is happening on the CPU.
Look at what the scripts are doing and what the Garbage Collector is doing. Im not an expert on Garbage Collection but what i do know is periodically (possibly when a threshold is passed) the GC will free up memory that your game is using but no longer has access to it, e. g local variables in a method. The GC will block the main thread so it can do its thing, which is what causes most lagg issues.
Good point! I found out that VSync is causing big frame drops
hmmm, do you have Vsync on? vsync needs to be off if you want to set the target frame rate.
https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
Turning off Vsync and then setting the target frame rate was a massive help. I am not getting any massive frame rate drops, just from 40 to 45 now. I will look for even more ways to improve performance. But for now, I think you had the answer! thanks
Answer by seandolan · Jul 08, 2018 at 03:22 AM
It sounds like you have some script/behaviour that is taking a little bit more processing power to calculate so the game is getting held up slightly before processing the next frame. Make sure you check and loops (for or foreach, etc) that is happening in any Update() or repeating functions. Loops greater than say about 100 with lots of actions can slow things down. If it's an essential process doing it, maybe look at options to do it in chunks. If you have a for loop that goes thru 1000 times, do it in lots of 100s - just an example. Would need to see the code to help out more. Hope this helps mate.
Thanks, I rewrote all of the update functions (2 or 3), where there were loops. Except in the menu, where I use for loops because of all the clickable objects, but they get disabled anyway once the game starts. It definitely helped because there is more time between each frame drop now! Something else must be causing it though.
Your answer
Follow this Question
Related Questions
Huge fps drop after using the Status Bar or Volume Controls on Android 0 Answers
Default Frame Rate for Mobile Device 0 Answers
Interstitial ad kills framerate in different scene. 0 Answers
Updated to 2021.3.3, why did my FPS drop significantly? (over 350fps) 0 Answers
Edge detection lagging on mobile devices 0 Answers