EditorGUI Update function problems

Using 5.1.1f1

I’m trying to write a system that will allow me to hear dialog in edit mode without having to walk to the area the dialog is in every time I want to test timing. After some research, I figured an Update function might help with getting delays to work. I’m starting with something basic to see if this will even work, but for some reason, it seems like Update isn’t called at all, or at least I can’t tell if it’s called.

#pragma strict

@CustomEditor (Dialogue)
public class DialogueEditor extends Editor
{
var delay : float;
var testActive = true;
function OnInspectorGUI()
{
    DrawDefaultInspector();
    
    var script : Dialogue = target;
    
    if(GUILayout.Button("Test Dialogue"))
    {
    	testActive = true;
    }

}

function Update()
{
	var script : Dialogue = target;
	if (testActive)
	{
		delay += 0.01;
		if(delay % 1 == 0) Debug.Log("Woof");
		if(delay == 10)
		{
			delay = 0;
			testActive = false;
		}
	}
}
}

The Update function will work, but only while rendering frames. The idea of the Update function in general is that it is called once per frame, and does not respectively run while the game is not in play mode.

However, you can add:

@script ExecuteInEditMode()

at the top of your script. This will trick the editor into thinking the game is running, so to speak.

Now, be sure to put

 #if UNITY_EDITOR

just before your update function and put

#endif

just after it.

This will make sure the code isn’t trying to run while you’re not in play mode.

Good luck with whatever you’re working on!