Question by
DonHaul · Aug 20, 2017 at 02:40 AM ·
editoreditor-scriptingeditorwindowundo
How to Undo a bool on an EditorWindow
I have been tackling this issue for a while but I cant get any results. I get the "Happened" messaged on the console, and if I go to the Edit>Undo, i see "testing" after it, meaning it recorded the change.
But when I press it, or do Ctrl-Z nothing happens. The bool testing has to be public and static because I also want to change her throght a MenuItem.
I have tried multiple approaches this was one of them
using UnityEngine;
using System.Collections;
using UnityEditor;
public class MapMaker2D : EditorWindow {
//instance of this script
public static MapMaker2D instance;
//testbool
public static bool testing;
//runs whenever the window is created
void OnEnable()
{
//sets instance of mapmaker
instance = this;
}
void OnGUI()
{
EditorGUI.BeginChangeCheck ();
bool atesting=EditorGUILayout.Toggle (new GUIContent("testing","testing variable"),testing);
if (EditorGUI.EndChangeCheck ()) {
Debug.Log ("Happened");
Undo.RegisterCompleteObjectUndo(this, "testing");
testing=atesting;
}
}
}
Comment
Answer by DonHaul · Aug 22, 2017 at 03:19 AM
turns out you have to make testing non-static, and update it according to a static bool whenever you want to change it via menu item