- Home /
Wait until scripts compile
Hello!
I'm making an extension for unity that imports some scripts. After I've imported the scripts, I need to make a game object and attach to it one of the scripts. Unfortunately, when I try to do that, Unity says that I have to wait until the script has fully compiled. What's the best way to go here? I mean, I refresh the Asset Database with AssetDatabase.Refresh();
I even load the assets with: AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default);
But this error still persists. Does AssetDatabase.Refresh have any callback methods or something like that, or do I have to pause the program for some time and then try to attach the script to the gameobject? I tried with System.Threading.Thread.Sleep, but that seems to stop the compiling too.
Any suggestions?
Answer by Bunny83 · Sep 25, 2013 at 06:42 AM
I think the best bet would be EditorApplication.isCompiling. Keep in mind that if Unity recompiles any script, the whole Mono environment is "reloaded" and deserialized. This is also true for editor scripts. Only public variables of serializable types will "survive" the mono restart.
Another way might be to use an AssetPostprocessor, but i'm not sure if it will fire after the scripts have finished compiling.
Hi! Thanks for the sugestions, appreciate the help! I decided to export the needed things as a package and then import everything as before and the package with AssetDatabase.ImportPackage... Seems to be working. Thanks again!
If that works reliably, feel free to post it as an answer ;)
Your answer
Follow this Question
Related Questions
Custom Export and Import FBX Data 1 Answer
Editor extension data saving 1 Answer
Multiple Cars not working 1 Answer
Editor crash on all scenes and projects 1 Answer
Why Are My Project Assets Constantly Re-Importing? 2 Answers