Search Unity

Assembly locks prevents recompilation frequently, needs to click on Layout dropdown to unlock

Discussion in 'Linux' started by huulong, Dec 31, 2021.

  1. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    On Unity 2021.2.6f1 I am frquently unable to recompile to to assemblies being locked: a lock icon appears at the bottom-right and the editor refuses to recompile code change. If I hover on the icon, I can see a tooltip: "Assemblies are currently locked. Compilation will resume once they are unlocked".

    I tried to Play and Stop the game, stop debugging with Rider, press Refresh again, to no avail.
    Sometimes, it would unlock by itself after some time or after closing an Editor window.

    However I found a 100% workaround to force unlock: click on the Layout drop-down button at the top-right. This will immediately remove the lock icon and start recompiling, replacing the icon with a loading circle.

    I'm only working on Linux these days so I can't tell if it's a Linux-only bug.

    I have sent a bug report but got no reply yet, so I opened this thread to see if other users are affected, and to share the workaround mentioned above.

    I don't know the exact conditions to get the lock icon. It just happens sometimes after code change, I'd say having a custom editor window open increases the odds, but I think it happened to me even when working on runtime code.
     
    AlfieBooth and EthanFischer like this.
  2. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    I keep getting this when recompiling from Rider as well. Though, I typically right-click in the project view in an empty area, which has the same outcome of unlocking and allowing recompiling. I tried checking if I could make a hotkey to unlock with things like:

    Code (CSharp):
    1. [MenuItem("Tools/Force Recompile Scripts %&r")]
    2. public static void ForceRecompileScripts()
    3. {
    4.     EditorUtility.RequestScriptReload();
    5.     AssetDatabase.Refresh();
    6. }
    Unfortunately, that doesn't seem to work.

    -----
    Edit
    I came across this:

    Code (CSharp):
    1. EditorApplication.UnlockReloadAssemblies();
    I had some hopes that it might work, but unfortunately, it did not.
     
    Last edited: Nov 21, 2022
  3. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    For anyone else who might have this issue, I made somewhat of a workaround. Instead of Rider initiating the recompile, I just made a script that raises the Unity Window and sends the recompile hotkey to it, then switches back to Rider. The only issue is that shortly after Unity starts compiling, it steals focus and raises itself (which it has always done, and I absolutely hate this behavior, just do what you have to do, there is literally no reason to jump in front just to display a useless progress bar). So really, the switch back to Rider at the end isn't event helpful unless I can figure out a way to block Unity from stealing focus in the first place.

    That said, doing compilation this way has, thus far, eliminated the locked assembly issue.

    For Rider, you can create an External tool, point it to /bin/bash for the executable, then the path to where ever you want to save the following code and assign a hotkey to that. Just replace the alt+r hotkey with whatever your Unity hotkey is set to in order to refresh/recompile.

    Code (CSharp):
    1. #!/bin/bash
    2. # compile_unity.sh
    3.  
    4. wmctrl -xa "unity" &&  sleep 0.5 && xdotool key alt+r && sleep 0.5 && wmctrl -xa "rider"
     
    Pnvanol likes this.