The setup: I have a Prefab with a script that has an array of structs in it (_arrayOfRevealedListsProperty
), serialized as part of the Prefab.
I then have Prefab Variants overriding the value of one of the items in the array. Of one of the structs. This is fine.
However, when I append an element to the array, with this code:
serializedObject.Update();
// Add the new element to the array
int newListIndex = _arrayOfRevealedListsProperty.arraySize;
_arrayOfRevealedListsProperty.InsertArrayElementAtIndex(newListIndex);
SerializedProperty newListProp = _arrayOfRevealedListsProperty.GetArrayElementAtIndex(newListIndex);
// Now I valorize the new entry
newListProp.FindPropertyRelative(nameof(RevealedItemsList.listName)).stringValue = newListName;
newListProp.FindPropertyRelative(nameof(RevealedItemsList.groupByGameObjects)).boolValue = true;
newListProp.FindPropertyRelative(nameof(RevealedItemsList.isVisible)).boolValue = true;
newListProp.FindPropertyRelative(nameof(RevealedItemsList.revealedItems)).arraySize = 0;
serializedObject.ApplyModifiedProperties();
I lose the overrides on the Variants. I would expect that by just adding to the array, whatever is overridden stays, because no indexes in the array have changed.
Is there something I’m missing that I could do to retain the overrides on my Variants, only in case of adding to the array?
Thanks.