Hi there Uniteers o/
I am in the need of help once again. I am now trying to mess around with my own custom Editor for a script, though I am having issues with the EditorGuiLayout.ObjectField();
I have created an ObjectField, which shows in the inspector. In the ObjectField I assign a GameObject from the scene.
As soon I play the scene, the ObjectField simply clear itself, and then UnassignedReferenceExceptions starts to pop up in the console. I am pretty sure it is just me who is missing some vital part / understanding of using custom editors.
The code I use is:
using UnityEngine;
using System.Collections;
using UnityEditor;
[System.Serializable]
[CustomEditor (typeof(IronManScript))]
public class IronManScriptEditor : Editor{
public TransitionMethod _TransistionMethod;
public GameObject _TargetObject;
public override void OnInspectorGUI()
{
IronManScript _TargetSys = (IronManScript)target;
GUILayout.Label ("Transition methods", EditorStyles.boldLabel);
_TransistionMethod = (TransitionMethod)EditorGUILayout.EnumPopup("Transition: ", _TransistionMethod);
_TargetObject = (GameObject)EditorGUILayout.ObjectField("Target: ", _TargetObject, typeof(GameObject), true);
_TargetSys._Transition = _TransistionMethod;
_TargetSys._Target = _TargetObject;
}
}
The “IronManScript” is the class in which takes all my inspector values, and I am (nearly) sure that the IronManScript doesn’t intefer with the custom editor.
EDIT: I just figured out, the Objectfield’s value isn’t cleared if I change the ObjectField value during runtime. The Objectfield only clears itself if you assign the value before you play the scene.
** EDIT EDIT ** Okay, by the look of it it could be something about serializing. As far as I have read, it is about custom classes who doesn’t extends from Monobehavior have to be serialized with [System.Serializable]. But even when implementing it it doesn’t work. I have updated the code.