- Home /
Serialized Property being uneditable in certain cases
I'm extending the gridBrush, and the gridBrushEditor to show more information for the user when handling a brush.
I've ran into a weird problem where any created serialized object that is instantiated within the gridBrushEditor would have its serialized properties be uneditable.
basically editable == false.
However, the gridbrusheditor holds a serializedObject reference to the gridBrush. And any serialized property that is used in it actually is editable.
Why is there such a difference between the two?
All of the property fields were set up using the following:
GUI.enabled = true;
EditorGUI.BeginChangeCheck();
using (var iter = serializedObject.GetIterator())
{
iter.Next(true);
while (iter.NextVisible(false))
{
Debug.Log(iter.name + " editable: " + iter.editable);
EditorGUILayout.PropertyField(iter, true);
}
}
if (EditorGUI.EndChangeCheck())
{
Debug.Log("Change is happening");
}
serializedObject.ApplyModifiedProperties();
serializedObject would change based on the case, but all of them get printed that way. within the OnSelectionInspectorGUI() method within the editor
Case 1: All values set up as part of the editor
[Serializable]
public class CustomData
{
public int testI;
public float testII;
}
[CustomEditor(typeof(CustomBrush))]
public class CustomBrushEditor : GridBrushEditor
{
public CustomData data;
public int test2;
}
In this case, the serialized object is set up using
new SerializedObject(this)
where this is the CustomBrushEditor.
Result : All serialized properties end up being uneditable.
Case 2: The data is part of a 3rd party UnityObject, this example being a Singleton Scriptable Object.
[Serializable]
public class CustomData : ScriptableSingleton<CustomData>
{
public int testI;
public float testII;
}
In this case the serialized object is setup using
new SerializedObject(CustomData.Instance)
Obviously being the instance of the data. Result: all serialized properties are uneditable
Case 3: The data is set up as part of the brush which is what the editor is set to be an editor for
public class CustomBrush : GridBrush
{
public int test;
public CustomData test2;
}
[Serializable]
public class CustomData // or can be extended of an SO: ScriptableSingleton<CustomData>
{
public int testI;
public float testII;
}
In this instance, I would be using the serialized object that is provided by the grid brush editor, which is a reference to the custom grid brush by default. as it is its editor after all.
Result: Be it just a serializeable class, or a scriptable singleton, the serialized property is always editable.
I couldn't find anything about why this is occuring, so i'd appreciate it if someone can show me why exactly this happens.
Your answer
Follow this Question
Related Questions
Changing Inspector's Serialized Property Label (With Code Sample) 1 Answer
Type casting SerializedProperty.objectReferenceValue doesn't work? 3 Answers
Override Transform Inspector using SerializedObject and SerializedProperty 1 Answer
How to get fields of a custom script through SerializedProperty.FindPropertyRelative? 1 Answer
Serialised Properties 1 Answer