- Home /
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;
}
}
}
}
Answer by Addyarb · Jun 28, 2015 at 04:52 AM
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!
Still the same problem. Nothing comes up on the console. I even tried putting a "play sound" command at the very top of the Update function, yet I don't hear anything
Your answer
Follow this Question
Related Questions
Activate Animation => Wait => Hide Gameobject 2 Answers
WaitForSeconds Question 2 Answers
Update() calls start several seconds after launch 0 Answers
Animation delay until certain distance 3 Answers
Time.time button delay trick causing NaN 0 Answers