How to write an array to SerializedProperty?
Hello everyone. I have a private array of game objects. In a custom editor, I form a list through a SerializedProperty so that it is convenient for me to work with objects. When I close the editor, I need to write this list back to the field. Since I want the array field to remain private I cannot access it directly. All that remains is the SerializedProperty, but I just can't figure out how to write the array back to it. Help, how can this be done?
protected void OnEnable()
{
groupActivator = (GroupActivator)target;
SerializedProperty targetsTemp = serializedObject.FindProperty("targets");
for (int i = 0; i < targetsTemp.arraySize; i++)
{
targetsList.Add((GameObject)targetsTemp.GetArrayElementAtIndex(i).objectReferenceValue);
}
if (targetsList == null)
targetsList = new List<GameObject>();
isOpenList = EditorPrefs.GetBool(groupActivator.GetHashCode() + "_editor_isOpenList", false);
}
[1]: /storage/temp/181123-2021-05-25-4-10-02.png
Your answer
Follow this Question
Related Questions
Custom editor: EditorGui.DrawPreviewTexture in SceneView only works in the top right corner 1 Answer
How to access a Custom Editor components 1 Answer
SetDirty not working in Custom Editor with Nested Custom Property drawer 1 Answer
Property Drawer ArgumentException 1 Answer
How to iterate over Serialized List? 1 Answer