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. Dismiss Notice

Reload Script Assemblies

Discussion in 'Editor & General Support' started by MatthewVale, Jun 3, 2022.

  1. MatthewVale

    MatthewVale

    Joined:
    Aug 5, 2014
    Posts:
    7
    So I've had this issue for a while, since 2021.3.1 perhaps? Anyway, occasionally this will happen and Unity will be stuck on "Reload Script Assemblies" forever. Typically I'm only waiting a few seconds for this. I have no idea why this happens, at first I thought maybe one of my scripts is causing it? But it's very inconsistent and I can't reproduce it, it just randomly happens.

    Screenshot of it attached. The only way for me to break the loop is to make a change in any of my scripts, save and it will recompile. Then it may or may not happen again afterwards.

    unitycompileissue.jpg
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,019
    Hmmm just a few thoughts. I've had this too but it was either running out of memory, accidentally doing nasty stuff with Native collections, or quite simply: editor scripts. The latter can cause issues in particular when you hook into assembly reload events or initialize on load where you create, delete or modify assets, scripts in particular. I deadlocked myself once by modifying a script during assembly reload and I had a bug there that caused the generated script to be changed on every reload.
     
  3. Tymac

    Tymac

    Joined:
    Nov 12, 2015
    Posts:
    10
    I started having this issue suddenly where my reload script assemblies went from averaging about 12 seconds on a fresh restart to over 2 minutes. Neither restarting nor rebooting the computer helped once it slowed down.

    There is hope. At least for others who might be experiencing this issue for similar reason to my own. I searched the forums trying to find a quick fix and nothing posted seemed to help but I did see comments about the editor scripts that could cause problems (like codeSmile and a few others mentioned). I opened up the Import activity window (Unity 2021+ feature I believe) and noticed a few long loading delays with prefabs that had an editor script attached to it that I had recently worked on. I redesign the editor script where I was referencing a monobehavior class which in turn held a reference back to the editor script's underlying class. I'm not certain this change fixed my problem but I believe it did because with that code change and deleting all but the one prefab referencing this script my script reload times went from over 2 minutes to under 10 seconds. A speed improvement over where I started the day.
     
    CodeSmile likes this.
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,019
    Thanks for sharing this! :)

    Particularly such editor scripts or generally any script that has [AlwaysExecute] or [ExecuteInEditor] attached or subscribes to editor events (assembly reload, selection change, and so on) have quite often been causes of slowdowns in my past experience.

    Some devs are quick to blame Unity yadda yadda but my stomach feeling is always that the most likely cause is either self-made or simply imported assets that do not scale performance-wise (or have been misused). I would always recommend to analyze the issue first, like you did!