Search Unity

Unity game lagging on android device.

Discussion in 'Android' started by abhinavsingh153, Aug 13, 2019.

  1. abhinavsingh153

    abhinavsingh153

    Joined:
    Jul 30, 2019
    Posts:
    1
    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.
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,977
    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.
     
    Ryiah and Joe-Censored like this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Use the profiler to see what is slowing it down. Otherwise you're just guessing.
     
  4. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    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).
     
    ixabhay, asdad3821, MRC-UA and 21 others like this.
  5. anas1973

    anas1973

    Joined:
    Aug 23, 2017
    Posts:
    4


    very helpful
     
  6. samcoder1011

    samcoder1011

    Joined:
    Jul 1, 2020
    Posts:
    2
     
  7. samcoder1011

    samcoder1011

    Joined:
    Jul 1, 2020
    Posts:
    2
    Was very helpful Thanks a lot !
     
  8. AncientLust

    AncientLust

    Joined:
    Oct 22, 2022
    Posts:
    12
    Tried everything from this thread, but the real solution for me was this line of code:

    Code (CSharp):
    1. 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.
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,724
    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?
     
  10. AncientLust

    AncientLust

    Joined:
    Oct 22, 2022
    Posts:
    12
    You're right, I confused it with Default frame rate in Timeline Asset:

    upload_2023-1-5_23-22-18.png
     
    Last edited: Jan 5, 2023
    AcidArrow likes this.
  11. kimyounghyun0302

    kimyounghyun0302

    Joined:
    Mar 22, 2023
    Posts:
    3
    You are my savior
     
  12. alvrmiguel

    alvrmiguel

    Joined:
    Apr 29, 2023
    Posts:
    2
    A genius
     
  13. Maverickyy

    Maverickyy

    Joined:
    Jun 14, 2023
    Posts:
    3
    Thank you ! you are a life saver
     
  14. bismoy

    bismoy

    Joined:
    May 10, 2020
    Posts:
    1
    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:

    1. The performance drop is consistent every time the app is minimized and then reopened.
    2. Unity Profiler indicates entries like Gfx.WaitForPresentOnGfxThread andTimeUpdate.WaitForLastPresentationAndUpdateTime, suggesting potential GPU synchronization or bottleneck issues.
    3. V-Sync has been confirmed to be disabled, yet the aforementioned synchronization-like issues persist in the profiler.
    4. Adjustments, such as resetting graphics settings upon regaining app focus and setting the target frame rate, have been attempted without resolving the issue.
    5. 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.
     
    wenxiao1992 likes this.