Hi all!
Im trying to create a custom inspector for level generation. I have run into some troubles tho.
I want to serialize a Transform object so it will persist between Play sessions and also when Unity has quit.
I made a test case for you to look at that will illustrate my problem:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MyWindow : EditorWindow {
[SerializeField]
private Props props;
[MenuItem("Test/Test")]
public static void ShowWindow() {
EditorWindow.GetWindow(typeof(MyWindow),false,"Test");
}
void OnEnable() {
if(props == null) {
props = new Props();
}
}
void OnGUI() {
props.OnGUI();
}
}
[System.Serializable]
public class Props {
[SerializeField]
public Transform parent;
public void OnGUI() {
parent = EditorGUILayout.ObjectField("Parent Transform",parent,typeof(Transform),true) as Transform;
}
}
I’ve created a window which shows a field to which you can drag an object from the hierarchy panel. All works fine but when restart Unity or press Play and Stop, the field is “None” and the reference is lost.
I have tried to follow the best practices on this, but clearly something has gone wrong.
Anyone know what the problem is?
Thanks!