- Home /
Custom Editor not working :(
I'm started to work with custom editors for a class called StoryEvent. each StoryEvent needs to have a Category. As the Editor intro ( https://www.youtube.com/watch?v=6dnQX0ChOsA) advised, I use SerializedObject. However, the script doesn't work. I know have a custom editor with only a category field. but when I drag my category it will not be added. what do I do wrong?
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(StoryEvent))]
public class StoryEventEditor : Editor
{
private SerializedObject _object;
private SerializedProperty _category;
void OnEnable ()
{
_object = new SerializedObject (target);
_category = _object.FindProperty ("category");
}
// Update is called once per frame
public override void OnInspectorGUI ()
{
_object.Update ();
Category c = (Category)_category.objectReferenceValue;
EditorGUILayout.ObjectField ("Category", c, typeof(Category), false);
if (GUI.changed) {
_category.objectReferenceValue = c;
}
//EditorUtility.SetDirty (_object);
_object.ApplyModifiedProperties ();
}
}
Answer by AyAMrau · Jul 03, 2014 at 06:12 PM
You are not assigning the value returned to anything when you call EditorGUILayout.ObjectField.
But since it's a SerializedProperty you can use EditorGUILayout.PropertyField instead:
EditorGUILayout.PropertyField(_category);
It will pick an appropriate field for the type.
On another note, why call Update() directly? If you want the object to update while in editor you can use ExecuteInEditMode
I called update as the Editor intro ( https://www.youtube.com/watch?v=6dnQX0ChOsA) advised
Answer by kami1339 · Apr 01, 2019 at 09:20 AM
Ha...
how you edit whene your editor not working?
Only restart your computer or log off it!!!!!!!it works.
Your answer
Follow this Question
Related Questions
ScriptableObject with Custom Editor resetting data in inspector 1 Answer
Why does my scriptable object asset lose items in a list after first playthrough? 1 Answer
How to make a custom editor for a serializedObject that is in a script component 0 Answers
Serializing a ScriptableObject without creating an asset for it? 2 Answers
Storing and Retrieving Data from a ScriptableObject 1 Answer