[Bug] Removing Component while its Inspector is Open

It appears that when I remove an Object, using Object.DestroyImmediate(...), while the Inspector tab is showing, Unity will crash.

Any ideas how to avoid this?

im using this in EditorMode.. so I have to use Destroy Immediate

(sorry if this description of the bug report is dull, but its all I have.)

It might be worth determining if the object you're about to destroy is selected using http://unity3d.com/support/documentation/ScriptReference/Selection.Contains.html

I found another solution for this… If a custom inspector removes a component on the same game object, during the same iteration of drawing the inspector, Unity will encounter the removed component and error trying to draw it.

Using EditorGUIUtility.ExitGUI() will stop the execution of the current draw iteration, starting over from the top, at which point the removed component will not be attempted to be drawn.

You have to hide it via TitleInspector resp. Foldout. If the component is hidden, then you can do the the DestroyImmediate as far as you have no scripts or other comps, which access your current component.

And it is no bug, although I have crashed by using customEditor when I do that without hiding.