I run a method in batch mode. it contains a call of PlayerSettings.SetScriptingDefineSymbolsForGroup, this call starts the compilation.
I want to know how to detect when the compilation is finished.
EditorApplication.isCompiling - does not work properly, it always returns true (even a few hours after starting the compilation) - I assume it results from batch mode.
Does anyone have any ideas?
AssemblyReloadEvents.afterAssemblyReload should do the trick, but may also get called during initial project open so you need to safeguard this.
Thank you for your quick response.
I applied your recommendation and a few others, however, I found that the compilation became stuck after this log ā[ScriptCompilation] Requested script compilation because: Define symbols changedā.
I also added these subscriptions, however, no events are raised after the message log
CompilationPipeline.assemblyCompilationFinished += AssemblyCompilationFinished;
CompilationPipeline.compilationFinished += CompilationFinished;
CompilationPipeline.compilationStarted += CompilationStarted;
AssetDatabase.importPackageFailed += ImportPackageFailed;
AssetDatabase.importPackageCompleted += ImportPackageCompleted;
AssetDatabase.importPackageStarted += ImportPackageStarted;
CompilationPipeline.assemblyCompilationNotRequired += AssemblyCompilationNotRequired;
My Unity version is 2022.3.25, and I assume the issue is inside the patch and I need to update the version to the current latest patch
Can you provide the context? It matters where, in which method or class you add these. Some of the events donāt āsurviveā domain reload and may need to be re-registered every time.
[InitializeOnLoad]
public class CompilationTracker
{
static CompilationTracker()
{
Debug.Log($"[Utils][CompilationTracker] CompilationTracker");
CompilationPipeline.assemblyCompilationFinished += AssemblyCompilationFinished;
CompilationPipeline.compilationFinished += CompilationFinished;
CompilationPipeline.compilationStarted += CompilationStarted;
AssetDatabase.importPackageFailed += ImportPackageFailed;
AssetDatabase.importPackageCompleted += ImportPackageCompleted;
AssetDatabase.importPackageStarted += ImportPackageStarted;
CompilationPipeline.assemblyCompilationNotRequired += AssemblyCompilationNotRequired;
}
As far as I understand the attribute [InitializeOnLoad] keeps the subscription alive during the editor session
Yep, that will re-register these events the moment domain reload occurs so you shouldnāt miss any of these events.
But Iām not seeing the ones I suggested:
AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload;
Still at least some of the others should get called.
The script is in an Editor folder or assembly?
It is in an Editor folder.
Yes, you are right I forgot to add it for test purposes, I will rerun it with these 2 test events.
I mean I added this class for test purposes to understand what happens during the pipeline
Hey, @CodeSmile )
OnBeforeAssemblyReload happened once and OnBeforeAssemblyReload did not occur.
Besides, I strongly decided to update the version to the latest patch, because the flow had been working fine for 2 years before moving to 2022.3.