- Home /
Question by
AllConsuming · Sep 24, 2020 at 05:50 PM ·
editoreditor-scriptinglists
CustomEditor not updating after changing a value?
I am trying to create a CustomEditor that works as a table for attributes and values in an RPG (AttributeTable). I wanted the Inspector to detect changes when the developer plugs in a class filled with attributes into a variable, and in response, the editor adds new items to a list for each one of those attributes. I got the editor script to detect changes and call a function for updating the list of values to match the current list of attributes, but the inspector shows no changes. I'm unfamiliar with writing editors; what am I missing that it doesn't seem to serialize these changes?
Editor:
[CustomEditor(typeof(AttributeTable))]
public class AttributeTableEditor : Editor
{
SerializedProperty attributesList;
AttributeTable script;
void OnEnable()
{
attributesList = serializedObject.FindProperty("m_attributes");
script =(AttributeTable) target;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(attributesList);
if (EditorGUI.EndChangeCheck())
{
//Update the original script repopulate the list of values
script.UpdateTable(script.Attributes);
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("Values"));
serializedObject.ApplyModifiedProperties();
}
}
And the function in the AttributeTable class it's calling to reupdate the list I'm trying to display:
public void UpdateTable(AttributeBlock attributes)
{
if(Values == null)
{
Values = new List<int>();
}
else if(attributes != null)
{
m_attributes = attributes;
Values.Clear();
int i = 0;
foreach (var _ in m_attributes.Attributes)
{
Values.Add(i);
Debug.Log("Added value");
}
}
else
{
Values.Clear();
}
}
Comment