- Home /
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?
Answer by Joshua · May 08, 2011 at 03:55 AM
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
... great, so I am using it correctly but it still splashes a big error on the screen?
That sucks, because the code I'm writing is intended to give to my students (who I don't want to give them code that spits out a big red scary error message).
Is there a way to surpress this error message? If not, I guess I'll just find a different way to get the same effect...
Not that I know. $$anonymous$$ust be possible though. I'd advice asking a new question 'how to surpres an error message', I'd be interested in the answer as well. :)
Here we go, I was curious so I looked it up myself. http://answers.unity3d.com/questions/14786/disable-warning-messages I hope you're using C#
Thanks: I saw that #pragma, but this error is actually an "Error", not a warning, so it doesn't display a number that can be surpressed (unless that number is just hidden somewhere... couldn't find it with a Google search though).
Being able to force synchronous mode simplifies this task into one line of code, but it looks like I'll probably just need to allow for asynchronous importing.
Answer by Jerry-Lee · Nov 25, 2016 at 07:58 AM
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);