- Home /
Can I get a callback when scripts have finished compiling?
I was unable to find a callback for use in an editor script to let me run code when compilation has finished. It might sound a little crazy at first, but such a callback could be useful for code generation techniques.
AssetDatabase.ImportAsset can be called on a script to force compilation immediately but will return before compilation is complete.
AssetPostProcessor doesn't appear to be able to call back for scripts.
C# can't have anything like Eval().
If anyone can think of a way to accomplish this please answer.
("YO DAWG I HEARD YOU LIKE EDITOR SCRIPTS...")
Answer by guavaman · Apr 25, 2015 at 06:32 PM
Use the attribute DidReloadScripts like this:
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded() {
// do something
}
Note that this does not run in batch mode when doing a build with the -quit flag even if scripts are reloaded.
As a re$$anonymous$$der: You have to use 'static' in order for it work. It makes sense in hindsight, but it took me a short while to figure out. Nothing else seems to be needed.
Answer by yakswa98 · Jun 10, 2017 at 06:50 AM
public class YourEditorWindow : EditorWindow
{
static YourEditorWindow instance = null;
[MenuItem("YourMenu")]
void Init()
{
instance= GetWindow(typeof(YourEditorWindow )) as YourEditorWindow ;
instance.Show();
}
void OnGUI()
{
if (instance==null)
{
Init();
return;
}
}
if script is recompiled all the static value is null and than you reopen your editorwindow
I could not find this information on any documentation page.
You saved me a good deal of time with this, thank you. .
Answer by DtBeloBrown · Apr 22, 2010 at 09:26 PM
There isn't a callback, but you can poll on this variable: EditorApplication.isCompiling
The sample code in EditorApplication.isCompiling's official page does not work :(
Your answer
Follow this Question
Related Questions
Execute a Runtime LevelGenerator in Edit-Mode 1 Answer
change textures without changing the original file 0 Answers
(Editor Scripting) Is it possible to generate MenuItems? 2 Answers
How can I make a text file immediately appear in my project from an AssetPostProcessor script? 1 Answer
Can you make an EditorWindow pop up and block the asset import process while it's open? 0 Answers