How to set value on Serialized array of of Structs using CustomEditor

Wondering if someone can help me out. I have a Custom editor script to a gameObject with an array of serialized structs. Im having a real tough time settings the field on each struct using editor scripting. Is there a good example out there I can take a look at:

Been look at this but doesn’t go over how to handle arrays

Thanks in advance

You would use GetArrayElementAtIndex().FindPropertyRelative(“PropName”);

for example;

            var serialzedObject = new SerializedObject(target);

            var array = serialzedObject.FindProperty("MyArray");

            for( var i = 0; i < array.arraySize; i++)
            {
                var element = array.GetArrayElementAtIndex(i).FindPropertyRelative("MyElement");
                //do something with the property
            }
3 Likes

Thanks heaps for the reply will give it a go

Worked like a charm thanks you, one last question is there anything the the API to check if a property has been dirtied.

You call begin and end change check and then call ApplyModifiedProperties() on the serialized object in the end chage check.

Thanks for the reply, What about checking just a specific property change