I have a custom GUI for script “foo” that uses the OnInspectorGUI() function. When a bool in the custom inspector is true it calls a function from inside the class that the custom inspector is for.
[CustomEditor(typeof(Foo))]
public class FooInspector : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
Foo FooObject = (Foo)target;
if(FooObject.foobar)
{
fooObject.fooFunction();
}
}
}
The class function creates a new game object, which for some reason calls OnInspectorGUI(), which makes it create a new game object again which causes an infinite loop.
public class Foo : MonoBehaviour
{
public void fooFunction()
{
GameObject GO = new GameObject();
}
}
I can’t figure out what is calling OnInspectorGUI() when I create a new game object and how to stop it from being called. I’m guessing some event is generated when the scene is changed that repaints the inspector.
How do I stop the event from happening in this instance or stop the infinite loop?
Maybe this has already been answered in the forums somewhere but I wasn’t exactly sure how to ask about it. Thank in advance.