Uninomicon

Documenting the dark corners of the Unity Engine.

User Tools

Site Tools


serializedproperty

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

serializedproperty [2021/10/10 18:21]
artehacker created
serializedproperty [2021/10/10 22:16] (current)
artehacker Add info about modifying arraySize when editing multiple objects
Line 6: Line 6:
  
 On the other hand, serialized properties for array elements with an index outside the range of the smallest array size will still represent incorrect properties, so it's still important to get the smallest array size manually, or to iterate through the array's elements using [[https://docs.unity3d.com/ScriptReference/SerializedProperty.Next.html|Next]]/[[https://docs.unity3d.com/ScriptReference/SerializedProperty.NextVisible.html|NextVisible]]. On the other hand, serialized properties for array elements with an index outside the range of the smallest array size will still represent incorrect properties, so it's still important to get the smallest array size manually, or to iterate through the array's elements using [[https://docs.unity3d.com/ScriptReference/SerializedProperty.Next.html|Next]]/[[https://docs.unity3d.com/ScriptReference/SerializedProperty.NextVisible.html|NextVisible]].
 +
 +Modifying SerializedProperty.arraySize will copy the complete array to all the edited targets, but changing the size serialized property instead will only copy the array's size to the edited objects.
 +Example:
 +<code cs>
 +SerializedProperty prop = serializedObject.FindProperty("someArray");
 +
 +// This will make each array element in the different selected targets the same. Mixed values will be lost.
 +prop.arraySize++
 +
 +// This will keep the different values of the array elements in the selected targets.
 +// Note that targets with an array size bigger than prop.arraySize will still lose some elements.
 +prop.FindPropertyRelative("Array.size").intValue++
 +</code>
 +
serializedproperty.txt ยท Last modified: 2021/10/10 22:16 by artehacker