SerializedObject obj = new SerializedObject(gameObject); SerializedProperty positionProp = obj.FindProperty("m_LocalPosition"); positionProp.vector3Value = new Vector3(1, 2, 3); obj.ApplyModifiedProperties();
SerializedObject obj = new SerializedObject(scriptableObject); SerializedProperty nameProp = obj.FindProperty("name"); nameProp.stringValue = "New Name"; SerializedProperty dataProp = obj.FindProperty("data"); dataProp.arraySize = 5; obj.ApplyModifiedProperties();This example creates a SerializedObject instance for a ScriptableObject, finds the name and data properties using SerializedObject.FindProperty() method, modifies the name to "New Name" and the data array size to 5, and then applies the changes to the object. Based on the namespace and class name, the UnityEditor SerializedObject belongs to the Unity Editor namespace and is a part of the UnityEditor.dll library.
SerializedObject and SerializedProperty are classes for editing properties on objects in a completely generic way that automatically handles undo and styling UI for prefabs.