RequestScriptCompilationOptions.CleanBuildCache not working

I feel like I’m losing my mind.
I want to force recompile all scripts in my project so I can re-discover warning messages.

Calling: CompilationPipeline.RequestScriptCompilation(RequestScriptCompilationOptions.CleanBuildCache)

does not result in CompilationPipeline.assemblyCompilationFinished being invoked.
Instead, it calls: CompilationPipeline.assemblyCompilationNotRequired

So how am I supposed to force a recompile to get warning messages?
AFAIK, you only get this information from CompilationPipeline.assemblyCompilationFinished ?

The docs say to use RequestScriptCompilationOptions.CleanBuildCache. But that isn’t working for me.
Will submit a bug

Bug case: IN-93874

Simple example:

using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;

namespace Project.Assembly1 {

	public class ScriptCompileListener : ScriptableSingleton<ScriptCompileListener> {

		[SerializeField] private bool completed = false;

		private void OnEnable() {

			hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;

			if (completed) {

				Dispose();
			}
			else {

				Unregister();
				Register();
			}
		}

		[MenuItem("Test/Recompile All Assemblies")]
		private static void Recompile() {

			instance.Compile();
		}

		private void Compile() {

			completed = false;

			Unregister();
			Register();

			CompilationPipeline.RequestScriptCompilation(RequestScriptCompilationOptions.CleanBuildCache);
		}

		private void Unregister() {

			CompilationPipeline.compilationFinished -= OnCompilationFinished;
			CompilationPipeline.assemblyCompilationFinished -= OnAssemblyCompiled;
			CompilationPipeline.assemblyCompilationNotRequired -= OnAssemblyNotRequired;
		}

		private void Register() {

			CompilationPipeline.compilationFinished += OnCompilationFinished;
			CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompiled;
			CompilationPipeline.assemblyCompilationNotRequired += OnAssemblyNotRequired;
		}

		private void Dispose() {

			Unregister();
			DestroyImmediate(this);
		}

		private void OnCompilationFinished(object obj) {

			completed = true;

			Debug.Log("Compilation finished");
		}

		private void OnAssemblyNotRequired(string assembly) {

			Debug.Log($"{assembly} compilation not required");
		}

		private void OnAssemblyCompiled(string assembly, CompilerMessage[] messages) {

			Debug.Log($"<color=green>Assembly Compiled: {assembly}</color>"); //This is never logged

			foreach (CompilerMessage message in messages) {

				Debug.Log($"[{message.type}] {message.message}");
			}
		}
	}
}

OnAssemblyCompiled is never called.

Just an idea, at least it could be a workaround. There are folders in Library and Obj (the latter probably entirely) that contain compilation artifacts. You could simply delete those folders and Unity would have no compile cache and thus do a full recompile.

Helps if Unity’s trying too hard to act clever. :wink:

1 Like

Yeah that could work. I might try a different approach where I save a persistent cache of assembly messages, then check if the cache isn’t storing all assemblies and automatically delete and recompile those that aren’t cached yet.

But really, Unity should be doing this already when asking for a clear script cache

Bug was created: