- Home /
Change the fields on a object bound to a SerializedProperty via custom inspector?
How are you supposed to do that? The undo functionality doesn't get handled automatically the way I do it:
[CustomEditor(typeof(Level))]
public class LevelEditor : Editor {
SerializedProperty _gridProp;
public void OnEnable(){
_gridProp = serializedObject.FindProperty("_grid");
// _grid is a LimeGrid extending ScriptableObject
}
public override void OnInspectorGUI(){
serializedObject.Update();
LimeGrid grid = _gridProp.objectReferenceValue as LimeGrid;
grid.Width = EditorGUILayout.IntSlider(grid.Width, 0, 200);
serializedObject.ApplyModifiedProperties();
}
}
Answer by Local-Minimum-2 · Feb 27, 2015 at 04:22 PM
I think this should work given that Width
is actually serialized and that I understand your code correctly:
public override void OnInspectorGUI(){
serializedObject.Update();
SerializedProperty gridWidth = _gridProp.FindPropertyRelative("Width");
gridWidth.intValue = EditorGUILayout.IntSlider(gridWidth.intValue, 0, 200);
serializedObject.ApplyModifiedProperties();
}
FindPropertRelative seems not to work on ScriptableObject though. But it was what I was looking for, thanks!
Can you post exactly how you solved it for the ScriptableOjbect
, because it might relate to my own question: http://answers.unity3d.com/questions/911624/using-custompropertydrawer-in-ongui-of-scriptablew.html
I didn't really solve it, I just removed the inheritance from ScriptableObject
I might try this answer though: http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html Idk if it would help you
Your answer
Follow this Question
Related Questions
Why are the children of my Serialized Property not being drawn? 1 Answer
Custom Inspector: Using 'serializedObject' to access inherited members 1 Answer
Error when trying to Serialize a field that is in a class 0 Answers
Replicate "Apply" and "Revert" button functionality in ScriptableObject Editor Inspector 2 Answers