Error using ImportAssetOptions.ForceSynchronousImport

I'm building an editor that modifies and re-saves scripts from within the Unity interface. When the user hits "Save", I want the script to reimport and update the window with the new script contents.

As part of this code, I am using ImportAssetOptions.ForceSynchronousImport. It works great, does exactly what I need it to do... but it also spits a menacing error into the Output window...


Reload Assembly called from managed code directly. This will cause a crash. You should never refresh assets in synchronous mode or enter playmode synchronously from script code. UnityEditor.AssetDatabase:Refresh(ImportAssetOptions) UnitySMEditor:OnGUI() (at Assets/Editor/UnitySMEditor.cs:70) UnityEditor.DockArea:OnGUI()


I haven't seen a crash associated with this, and the error itself seems a little strange. If I'm not supposed to refresh assets synchronously in script, then why does it give me the option to do so? In what places is it safe to use this option, if not in script?

Right, I remember watching a video from Unite mentioning this, I think its this one. Basically, a guy working at/with Unity Technologies used this successfully in an editor script he wrote . Practically every other situation in which you use it, it will make unity crash. So in unity 3 they wanted to remove this, but the guy giving the presentation I linked to convinced them to keep it in so he could still use it. So instead they just put in a HUGE warning, I see. :p

So I guess that if the way you use it does what you want it to do, and unity doesn't instantly freezes and shuts down, you're using it in one of the few ways you can savely use it. Just be careful ^.^

  • I have no experience with this, by the way, I'm just deducing this from what I remember having seen in a video a while back.. I might be way of. But I think I'm right

I think you can use codes to clear console messages like this, because I did it.
Type type = Type.GetType(“UnityEditorInternal.LogEntries,UnityEditor.dll”);
MethodInfo info = type.GetMethod(“Clear”, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (info != null)
info.Invoke(null, parameters);