Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Bad performance unless the game is launched with Build And Run option or in wakelock mode

Discussion in 'Editor & General Support' started by DanielRN_0101, May 30, 2022.

  1. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    Hi there, I'm writing this post as I've found no solutions by looking up in this forum. There is actually a thread asking about a similar problem, but sadly it was not fully resolved (https://forum.unity.com/threads/ins...unched-via-build-and-run.663280/#post-4440238).

    First of all, some info:
    • Build platform: Android
    • Unity version: 2020.3.35f1
    • Minimum API Level: 21
    • Target API Level: 30
    • Scripting backend: both Mono and IL2CPP
    We are making a multiplayer game which contains a main menu and a gameplay mode. The performance is optimal (around 60 FPS) if one or both of the next conditions are met:
    • The game was launched by using the Unity Editor's "Build and Run" button
    • Using a development build, the Android device is in wakelock mode: by turning off and turning on the screen while the game is active, the game is reopened without showing the Android lock screen and the square button (the one that shows all currently active apps when pressed) is hidden.
    If none of these requirements are met, performance in gameplay mode harshly drops, going from about 60 FPS to about 30-40 FPS, or even less depending on the device and other conditions.

    In summary:
    1. Launch the game from the Android app menu
    2. Enter gameplay mode, the performance is bad, about 30-40 FPS
    3. Force the wakelock mode by turining off and on the screen
    4. The performance is now optimal, about 60 FPS
    5. If the wakelock mode is then exited, by making the lock screen appear, the performance will drop once again.
    Using the profiler has been somewhat unsuccessful so far, as usually the frame rate heavily drops to about 20-30 FPS both in wakelock and non wakelock mode.

    Thanks in advance!
     
  2. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    I'm attaching some profiler screenshots.

    These are taken from an IL2CPP Android build with the bare minimum to enter the gameplay scene, and in offline mode (no internet connection, just the client):

    upload_2022-6-1_16-37-23.png

    After moving to the gameplay scene, there is a period of time in which the game runs at 60 FPS (seemingly random, about 10-30 seconds), then the performance rapidly degenerates to about 20-35 FPS, as seen in the picture. After forcing the wakelock mode, the frame rate raises to 60 FPS once again and stays there unless the wakelock mode is exited.

    Here are some of the metrics:

    Before the FPS drop:

    upload_2022-6-1_16-44-29.png

    After the FPS drop:

    upload_2022-6-1_16-45-0.png

    While in wakelock mode (after the FPS drop, 60 FPS until wakelock mode is exited):

    upload_2022-6-1_16-45-32.png

    Any tip will be of great help!
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Did you check the logs? Sometimes this sort of slogging can result from massive amounts of debug spew coming out, such as if something about WakeLock changed the timing of startup scripts, triggering mass nullrefs, perhaps even on something you either haven't noticed, or something that isn't important.

    See if you can get it to slog, then connect up
    adb logcat
     
  4. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    Hi Kurt, thanks for answering. Yes, there are no application logs being printed when that happens. However, I did notice something: if in the Unity Editor's Android Logcat window no application filter is applied (so that it prints all system logs, not just the ones from the game) some messages are always printed at the same time the frame drop occurs:

    upload_2022-6-2_11-35-10.png

    So my best guess is that this is something related to the device slowing the CPU/GPU down when the device reaches a certain temperature, but I'm not sure. What I can't grasp is why this performance limitation would no longer be applied while the device is in the wakelock state, and the device doesn't even seem to get hotter while in this state even if it is running at full 60 FPS.
     
    Last edited: Jun 2, 2022
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Probably a bug in Android. Any codebase of that size is riddled with these sorts of warts, no exceptions. :)