I’m trying to make an editor script that will destroy a gameObject and replace it with another. But when I destroy the gameObject I get an error. The object still gets destroyed and everything works fine, but seeing the error in the console over and over is annoying and cluttering. here is the error
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
But I’m not trying to access it after I delete it so I don’t understand.
Here is the simple editor script I have to destroy the object
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(EditBall))]
public class BallQuickEdit : Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Apply"))
delete();
}
void delete()
{
DestroyImmediate(Selection.activeGameObject);
}
}
Any ideas why I would be getting this error? Is there any way to stop it?
Thanks in advance
-John