breaking out of OnGUI() ticks?

I’m not sure my title makes much sense but I couldn’t find a better one…

My problem:
I have code which runs constantly in OnGUI() for an editor window:

GameObject fbx, model, prefab;
bool childUpdateOnly = false;
bool dontCheck = false;

void OnGUI()
    // Create selection field to allow the selection of the object to process
    model = (GameObject)EditorGUILayout.ObjectField( "Select FBX Object", fbx, typeof(     GameObject ), true );
    oldPrefab = (GameObject)EditorGUILayout.ObjectField( "Select Prefab To Update", oldPrefab, typeof( GameObject ), false );

    childUpdateOnly = (bool)EditorGUILayout.BeginToggleGroup( "Child Update Only", childUpdateOnly );

    if( model && prefab )
        if( == && dontCheck == false )
            childUpdateOnly == false;

As you can see in the code above, ‘childUpdateOnly’ gets set on every update tick so that if the user removes a GameObject from one of the ObjectFields, it automatically gets set to the correct state.
But I also want to be able to check/un-check it manually by clicking the toggle field in the EditorWindow, problem is, since the code checks for the ObjectFields state on every tick, ‘childUpdateOnly’ gets set back automatically so I can’t manually check/un-check it.

How can I get around this problem? Is there a way to maybe use the Event system, with something like this:

if( Event.current.type == EventType.MouseClickUp )
    childUpdateOnly = !childUpdateOnly;
    dontCheck = true;

But then how do I set ‘dontCheck = true’ if the user removes or adds a GameObject from one of the ObjectFields?

I hope I’m explaining my problem clearly enough, if not I’m sorry :slight_smile:
Any help will be greatly appreciated as always, thanks for your time guys.


unity serializes all public properties and stores it internally.

editor doesn’t store any values at all. Editor class initializes every time it needed, so it can’t be used to store any data at all. Editor is just a provider between you and component it created for.

‘childUpdateOnly’ in your case is a private variable so it will not be stored.

declare this property as public in class that this editor created for and change it in this editor on user’s clicks

don’t leave any needed data in editor.