Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Long Enter Playmode times and Profiler

Discussion in 'Editor & General Support' started by Jables17, Oct 27, 2023.

  1. Jables17

    Jables17

    Joined:
    Sep 23, 2018
    Posts:
    13
    Hello,

    I'm trying to diagnose an issue I'm having. The editor takes around 10-30 seconds to enter playmode. This started happening very recently so I'd like to learn how to better diagnose this issue before it gets out of hand. I've tried looking through the profiler, but I'm a bit new to the profiler since I only work with small projects.

    I frequently see a message during load that states "RestoreManagedReferences" This can take around 15 seconds or more so I believe this is my issue, possibly relating to my scripts? I see nothing in the profiler that seems obvious to me besides the editor loop which I can't see the details for.

    Can anyone give me some advice on where to start?
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,976
    Enable deep profiling. ;)
     
  3. Jables17

    Jables17

    Joined:
    Sep 23, 2018
    Posts:
    13
    I enabled Deep Profiling and the Editor Loop still does not have a drop-down arrow to view what it contains. Not sure if it would explain the source of the long load times anyway but it would be nice to have a look.

    Can't really find any information online about "RestoreManagedReferences" and why it is happening.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,976
    Is the profiler set to profile the editor? (default is playmode)
     
  5. Jables17

    Jables17

    Joined:
    Sep 23, 2018
    Posts:
    13
    Oh, I didn't notice that option. Thanks, that took care of it. But idk the first thing about debugging this in the profiler.

    I was able to find RestoreManagedReferences in the profiler window (screenshot attached). Does anyone have any advice on where to look or what to do to properly fix the load time issue I'm having? Does anything in my profiler look abnormal?
     

    Attached Files:

  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,976
    I don't know what this is but it's pretty hefty and happens during AssemblyReload. This tells me you do not have domain reload disabled (Editor settings), a setting I always enable at the start of a project because it makes enter playmode instantaneous. The only thing you need to be cautious of are static fields and events.

    This restoring references makes me wonder if you have any lists in your Inspector where you have thousands of references/events in total?

    Since this is a recent thing, consider what you may have changed since then. Source control would help, you could go back to a previous version until you find the one where enter playmode is still fast, then look at the changes.

    Also try deleting the Library folder (with the project closed) in case there's some corrupt/stale cache data.
     
  7. Jables17

    Jables17

    Joined:
    Sep 23, 2018
    Posts:
    13
    I disabled domain reload and this does in fact cause play mode to be instantaneous.

    There is plenty of references and events on multiple scripts but nothing too crazy. Unfortunately, this is an older project so I'm not sure when the issue began. It likely started occurring before I shelved the project, but I know this isn't normal for how small the project is.

    I will try enabling domain load and deleting the library folder to see if the issue still occurs.

    Side note: It took the editor 30 seconds to open the preferences window:eek:
    and my computer is by no means slow

    In any case, at least the problem has a quick fix and I can enter play mode much faster. Thank you!