Unity recompiles/builds the project once the window regains focus. I am working on a really big project that needs to be refactored, resulting in me needing to look a lot of stuff up in Unity and then moving back to Visual Studio. However each time I switch to Unity I need to wait a few seconds for it to recompile.
Is it possible to disable this? Maybe only recompile when clicking on run.
Although interesting, the accepted solution didn't work for me in Unity 5.4.1 (32-bit version). This answer is a lot better, lets me manually control when to recompile.
I had hoped this setting would just completely disable recompiling, but actually it just disables refreshing assets when you first focus back to Unity. Changes you make in the project window can trigger a recompile.
I'm using 2018.4. Not sure if it's the same in other versions, but this setting only applies to the compile that gets triggered by changes made outside of the editor. Moving, renaming, deleting or adding a script from inside Unity (e.g. in the project window) will still always trigger a recompile even with these settings disabled, which can very rather annoying when you're refactoring and you've got a lot of changes to make.
agreed, i've gotten used to doing all my refactoring, renaming and adding scripts in vs code. the experience is far more customizable with things like unity code snippet extensions, terminal etc.
In Unity 2021 (possibly since 2020), the first setting moved to Preferences > Asset Pipeline > Auto Refresh, although the Script Changes While Playing behaviour setting is still in General.
You need to put this script in an "Editor" folder anywhere in your project, then just click on the appropriate button. After having locked assembly reload and then unlocked, the assemblies will reload on the next time Unity Editor gains focus.
using UnityEngine;
using UnityEditor;
public class AssemblyReloadEditor : EditorWindow {
System.Action DebugDelegate;
[MenuItem("Custom/Assembly Reload Editor")]
public static void Init(){
GetWindow<AssemblyReloadEditor>();
}
bool locked = false;
void OnEnable(){
DebugDelegate = CompilingPrevented;
}
void OnGUI(){
if(EditorApplication.isCompiling && locked){
EditorApplication.LockReloadAssemblies();
DebugDelegate(); //this is just so the console won't be flooded
}
GUILayout.Label("Assemblies currently locked: "+locked.ToString());
if(GUILayout.Button("Lock Reload")){
locked = true;
}
if(GUILayout.Button("Unlock Reload")){
EditorApplication.UnlockReloadAssemblies();
locked = false;
if(EditorApplication.isCompiling){
Debug.Log("You can now reload assemblies.");
DebugDelegate = CompilingPrevented;
}
}
Repaint();
}
private void CompilingPrevented(){
Debug.Log("Compiling currently prevented: press Unlock Reload to reallow compilation.");
DebugDelegate = EmptyMethod;
}
private void EmptyMethod(){}
}
There is also a UnityEditorInternal.InternalEditorUtility.RequestScriptReload();, but I couldn’t make it reload the scripts on demand.
re:Jesdisciple correction on windows Windows: Edit > Preferences > General > Auto Refresh
– dducrestFor this one refactor I'm doing this should be more then enough.
– illustirAlthough interesting, the accepted solution didn't work for me in Unity 5.4.1 (32-bit version). This answer is a lot better, lets me manually control when to recompile.
– Harinezumimoved to Edit > Preferences > General > Auto Refresh
– midnightcrawler1I had hoped this setting would just completely disable recompiling, but actually it just disables refreshing assets when you first focus back to Unity. Changes you make in the project window can trigger a recompile.
– eaugustinowiczJC