I asked this out on answers, but I’ll prob have better luck finding out if this is a bug here.
I think the behavior I’m seeing is a bug, but I thought I’d ask it here first in case I’m just missing something. When writing my custom editors, all of my changes are being discarded when I hit the “play” button for any object I need ‘type’ I need to instantiate. I’ll keep the code simple:
First, I have a class called HiddenObject:
using UnityEngine;
using System.Collections;
public class HiddenObject {
public GameObject hiddenObj { get; set; }
}
Next, here’s the script I’ll attach to an object in my Scene:
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
public HiddenObject hiddenObject = new HiddenObject();
}
Finally, here’s my custom editor script:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Inventory))]
public class InventoryEditor : Editor {
private Inventory _inv;
void Awake()
{
_inv = (Inventory)target;
}
public override void OnInspectorGUI()
{
_inv.hiddenObject.hiddenObj = (GameObject)EditorGUILayout.ObjectField("Hidden Object", _inv.hiddenObject.hiddenObj, typeof(GameObject), true);
if(GUI.changed)
EditorUtility.SetDirty(_inv);
}
}
When I click on my Object in the Scene Hierarchy I can see the Custom Inspector displaying properly and I can click on the Game Object Field and select something or drag a game object to it. This all works correctly.
The moment I click the “Play” button, it’s all nulled out though. Clicking stop doesn’t bring back my changes, everything has been nulled out.
I’m certain this has to do with the fact that I’m having to instantiate the HiddenObject (new HiddenObject()) but not exactly sure how else I’m supposed to do it. Am I missing something, or is this a bug?