Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Unity build getting freezes or FPS getting 0 in between running game.

Discussion in 'Editor & General Support' started by paavann, Sep 25, 2023.

  1. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    Hello Unity folks!
    I am experiencing a very frustrating thing recently in my Unity game. My games are working fine on Unity version 2020.3.22f1. There was no any issue on that. Now I have upgraded my Unity version to LTS 2022.3.7f1. And now my Unity release build is getting stuck/frozen or lagging to much, FPS goes almost to 0 I think. This is also not happening always. Occurring sometimes for some users. Unable to play, move anything. In that case user has only one option to quit the app and start again. Never happens on Editor only in release builds. So unable to debug this as well. Unable to understand whats happening. I have also attached a screenshot. In this game was working fine and its just got stuck there. nothing happens after that. you have to quit the app there.
    Solution I have already try is disable the "Optimized Frame Pacing" but this did help me. I have been stuck or finding the solution for this for weeks. Please help me guys if anyone have the solution for this. Thanks a lot in advance!
     

    Attached Files:

    Last edited: Sep 26, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,188
    Start all performance investigations with the profiler. Find out what is dogging your app down.

    In the case you describe above, my first random guess is that you are doing too much in FixedUpdate().

    This mistake can have an interesting sudden performance cliff appearance, where everything is fine and suddenly it drops down to 5 fps when you break that barrier of what can be safely done in the FixedUpdate() time window.

    Do absolutely NOTHING in FixedUpdate() if possible, and when you must use FixedUpdate(), be sure it is 100% solely for transacting against the Physics or Physics2D engine and absolutely nothing else.



    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html



    Two good discussions on Update() vs FixedUpdate() timing:

    https://jacksondunstan.com/articles/4824

    https://johnaustin.io/articles/2019/fix-your-unity-timestep




    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that you are gathering information at this stage. You cannot FIX until you FIND.

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Don't forget about the Frame Debugger either, available right near the Profiler in the menu system.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.

    "Software does not run in a magic fairy aether powered by the fevered dreams of CS PhDs." - Mike Acton
     
  3. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    @Kurt-Dekker Thanks for reply and some useful suggestions but I have a doubt that its not happening in my any single game. Its happening across my all games, its either 2D game or 3D which were working fine on the previous version of Unity. Some 2D games where not a single FixedUpdate() has been used and not high graphics rich UI/UX.
    Is there any Editor settings like "Optimized frame pacing" enable/disable which I am missing that causing this issue. Please let me know.
    Thanks!
     
    Last edited: Oct 10, 2023
    dendyak likes this.
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,247
    I'm assuming you upgraded from 2021.3.22f1 as 2022.3.22f1 does not exist yet, but this also sounds like you might be hitting this issue.
     
  5. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    hi @MartinTilo Thanks for the replay. Actually I have upgraded from Editor version 2020.3.22f1 to 2022.2.1f1 firstly and then within a week shifted to 2022.3.7f1 which is the LTS version.
    Yes, correct looks like the same issue as you have mentioned in the other thread. So what is the solution for this. Do we have any fix for this as of now? My all apps are down and do not what to do next. Please please please help me with this.
    Thanks!
     
    Last edited: Sep 26, 2023
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,247
    Not yet, we're working hard on investigating it. So far the reproduction is weirdly elusive... might be a heisenbug? We'll keep pushing it, and update in that thread.
     
  7. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    hi @MartinTilo I think, I have the reproduction steps and its mostly related to memory leak. Initially I was not able to reproduce this but yesterday I got this issue on staging build as well. I had played a single game continuously for quite a long time like almost 15-20 mints and then in between game got stuck. I have tried this multiple times and every time I was able to reproduce that. No logs, No ANR, No Crash etc nothing just game got stuck/freeze.
     
    Last edited: Sep 27, 2023
    MartinTilo likes this.
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,247
    If you feel like you have some good repro steps, an additional bug report could give us more details to go off and maybe a more stable repro. If you could file one via the Editor Menu
    Help > Report a Bug 
    and ping this thread once you get an issue ID back, that would be very helpful :)
     
  9. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    You can check the video attached.
     
  10. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    Sure, I will do that, but can you let me know which option I should pick here and also tell me about other details so that it will more effective. Please check the screenshot attached. upload_2023-9-27_14-8-1.png
    Thanks!
     
  11. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,247
    From what I gathered it's a problem with the Player that Happens Every Time or Most Of The Time (depending on the specific Android hardware)

    As for specifics:
    - attaching a project to reproduce this with
    - devices tested
    - steps within the app and approx duration until the freeze
    - you said there are no logs but maybe attaching a logcat?

    Also, if you add regular (per frame or second) logs to the Player, it might become more apparent in the log where it freezes.
     
  12. paavann

    paavann

    Joined:
    Nov 21, 2018
    Posts:
    33
    @MartinTilo is it the same issue as mentioned on this thread. As @TwoYen and you also have mentioned here that it has been fixed in Unity version 2203.10f1. please confirm.
    Thanks!
     
  13. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,247
    No, the memory leak is separate from the freeze. That said, the only way for us to be certain is if we have a repro project that we can test and validate fixes against, or by you upgrading your project to Unity versions that would have a big fixed on them. I.e. if it would be the leak, you could confirm that by upgrading to 2022.3.10f1 (which btw fixed multiple leaks) and if it's the freeze due to culling and shadowcasting light sources, you'll have to wait and follow the other thread and bug ticket for updates.

    Also, there seems to be another race condition crash in the mix here, but that would not cause a freeze. Also, there's still the potential that the OptimizeFrame Pacing freeze is not yet fixed.