- Home /
Override/remove an error from console?
I get this error about object not being destroyed in the editor because it can be done only in game blabla and it's really annoying. Any way to remove it?
Destroy may not be called from edit mode! Use DestroyImmediate instead. Also think twice if you really want to destroy something in edit mode. Since this will destroy objects permanently.
The error if you're wondering.
I don't want to destroy the object in editor anyway, so go away.
Have you tried actually using DestroyImmediate? Is it running from an editor script? If all you want is to "hide" the error message you can use a try{}catch(error){} block, but then the error still occurs, I wouldn't recommend such a practise. In any case I could use more info about your problem.
There isn't more info. The DestroyImmediate will kill it in the editor. I don't want that. I want it to be killed only in game. I do run the script in the editor too because some stuff are needed to run, but this isn't needed.
There isn't more info? Your script would be more info. You do something in one of your scripts that we haven't seen yet. Unity warns you that you do something that you should not do. So in the end it's a mistake on your side. Errors don't go away if you ignore them...
Answer by Bunny83 · Apr 13, 2011 at 05:17 PM
Sorry, but if you execute code in edit mode YOU have to be sure what you want to execute and what you don't want. I guess you want the script to delete something but only when you're in playmode. So just check that with Application.isPlaying:
[...]
if (Application.isPlaying)
{
Destroy(someObject)
}
[...]