Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug After running in play mode for a few minutes, the entire process suddenly begins to lag

Discussion in 'Editor & General Support' started by ICMV5, May 22, 2024.

  1. ICMV5

    ICMV5

    Joined:
    May 22, 2024
    Posts:
    2
    After running in play mode for a few minutes, the entire process suddenly begins to lag, some bool variables in the Animator also become uncontrollable, constantly automatically switching on and off. Tried to open the Profiler and got this result.I am not very proficient in code, so I don't understand exactly where the problem is. How can I fix this? UG%5NFGTCPYDK%2I30~]U9S.png
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,357
    Sounds like you are accumulating something, like perhaps some controller that gets re-added, or perhaps a coroutine that gets restarted, so that you have many things running at once.

    Time to start debugging!

    By debugging you can find out exactly what your program is doing so you can fix it.

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

    Use the above techniques to get the information you need in order to reason about what the problem is.

    You can also use
    Debug.Log(...);
    statements to find out if any of your code is even running. Don't assume it is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Make a build. If it doesn't happen in the build it's something with the editor. Not uncommon. Especially if you have the Animator window open/visible during playmode it can sometimes be a drag on performance. But it can also be an Inspector window. Anything you expose to the Inspector needs to be rendered. If you have an "enemies" list and keep adding to it, the Inspector will have to draw increasingly more over time.

    Be sure to run the latest patch release of whatever editor version you are on to avoid this being some already-fixed issue.
     
  4. ICMV5

    ICMV5

    Joined:
    May 22, 2024
    Posts:
    2
    The problem still exists after build,and there are no new objects added to the scene or list.I tried to close all objects with scripts when entered play mode, but even so, there will still be issues after a few minutes.I also tried not to add a new object in the update method and used GetComponent(). The situation has not changed either.
    (Editor version 2021.3.16f1c1) %H7VTMG4B9{R5_CO[@)`$FG.png NF93FRC~{14FGV)S65RJO}P.png
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Make sure you enable deep profiling in the Profiler, and then change the view from "Simple" to (I think) "Hierarchy" so that you can see a tree of method calls. This lets you dig down deep into the callstack following the trail of the highest GC allocations or time spent. You will likely end up in a method of yours or an internal method but you are calling it from somewhere.

    If the issue is not obvious feel free to post more info.

    Since you are on patch 16f1 you may want to upgrade to 39f1 since that's over 20 bugfix releases you're missing out on.