Hi everyone. I am new to game development. I have been following a udemy course for unity game development. I have built a game which was a part of the course. The game is working fine and running smoothly on Windows and Webgl format but the game is lagging so much on android device. I have tried to set the quality under project settings (Edit>Project settings > quality) to very low for android, tried to set the frame rate to 60 fps then 30 fps by using Application.targetFrameRate = 30 in the Start() method of the escripts associated with the gameObjects. I have tried to search online for a solution also but didn’t find the solution yet. Any kind of help will be greatly appreciated.
What hardware is it running on?
It could just be that your game is not optimised enough for mobile phones. Are you using mobile shaders etc?
Do you have vsync on?
Turn vsync off if its on, and change your shaders to mobile compatible + optimised ones for the mobile build. Then try and test that and come back and let us know if it helped.
Generally a game for pc wont just build for android with perfect perf unless you optimise it. Such as proper shaders, lightmap baking, occlusion culling etc etc
Profile it if you want to know why. Run the profiler, as well as frame debugger, memory profiler and youll know pretty quickly what is taking up resources. But my guess is its just too heavy for android if you just built it for it without optimising for mobile.
Use the profiler to see what is slowing it down. Otherwise you’re just guessing.
I have been on a never ending quest to optimise my mobile game and I have come across these fixes that may be able to help you out. (May be game specific but this helped me)
-
On Image and Text components that aren’t interacted with you can uncheck “Raycast Target” on it, as it will remove them from any Raycast calculus.
-
Click on your textures in your “Project” window. Click on the “Advanced” arrow, and now check “Generate Mip Maps”, Unity especially recommends it for faster texture loading time and a lower rendering time.
-
Set the “Shadow Cascades” to “No Cascades” (Quality settings)
-
If you have dynamic UI elements like a Scroll Rect with a lot of elements to visualize, a good practice is to turn off the pixel perfect check box on the canvas that contains the list and disable the items that aren’t visible on the screen.
-
Set all non moving objects to “Static”
-
Above Unity3d 2017.2 you should turn off “autoSyncTransforms” on the Physics tab
-
Always use Crunch Compression Low on textures
-
Try to keep the “Collision Detection Mode” on “Discrete” if possible, as “Dynamic” demands more performance.
-
You can go to the TimeManager window (Edit > Project Settings > Time), and tweak the “Fixed Timestep” value. This value represents the duration between two calls of the FixedUpdate() method.
-
You can use Coroutines to call a method only every second for example, using the instruction: “yield return new WaitForSeconds (1);” It could be used to refresh some UI display:
-
Set particles culling to “Pause and Catch Up”
-
Use ShaderVariantCollection.WarmUp to fully load shaders before gameplay
-
Baked your shadows or turn them off
-
Out of Built-in Shaders, they come roughly in this order of increasing complexity:
-
Unlit. This is just a texture, not affected by any lighting.
-
VertexLit.
-
Diffuse.
-
Normal mapped. This is a bit more expensive than Diffuse: it adds one more texture (normal map), and a couple of shader instructions.
-
Specular. This adds specular highlight calculation.
I am not a professional and these tips are pulled from all the research I have done. Some people might crucify me for the above but this is what I have heard.
Those are the quick fixes you can try but without any knowledge of your game we can’t help much. Even a screenshot would help. Particles, Lights, Shadows and Textures are the main culprits of lag (from my experience and if done incorrectly).
very helpful
Was very helpful Thanks a lot !
Tried everything from this thread, but the real solution for me was this line of code:
Application.targetFrameRate = 60;
Have no idea why when I switched from PC to Android build my frame rate on the device became 30. Even despite that target FPS in project settings is set to 60. But maybe it will help someone.
Because Unity thinks mobile games should default to 30fps, even though phones have refresh rates of 120++ these days.
There is no targetfps setting in project settings? Are you talking about something else?
You’re right, I confused it with Default frame rate in Timeline Asset:
You are my savior
A genius
Thank you ! you are a life saver
Issue Description: In a Unity-developed game targeting Android devices, a specific performance issue arises related to the app’s lifecycle. The game runs smoothly at a consistent 60 FPS during normal gameplay. However, after minimizing the app and subsequently reopening it, the frame rate experiences a significant drop, sometimes reaching as low as 15 FPS or 30 FPS.
Key Observations:
- The performance drop is consistent every time the app is minimized and then reopened.
- Unity Profiler indicates entries like Gfx.WaitForPresentOnGfxThread andTimeUpdate.WaitForLastPresentationAndUpdateTime, suggesting potential GPU synchronization or bottleneck issues.
- V-Sync has been confirmed to be disabled, yet the aforementioned synchronization-like issues persist in the profiler.
- Adjustments, such as resetting graphics settings upon regaining app focus and setting the target frame rate, have been attempted without resolving the issue.
- The game is developed in Unity, and the issue has been primarily observed during testing on Android devices.
Requirement:
Seeking insights, potential solutions, or troubleshooting steps to address and resolve the performance degradation specifically tied to the act of minimizing and then reopening the app on Android.
Hello, have you found any solution to this problem?
Don’t understand why it is so easy and it is works. Thank u a lot!