SerializedObject Manual     Reference     Scripting  
Scripting > Editor Classes > SerializedObject
SerializedObject

SerializedObject and SerializedProperty are classes for editing properties on objects in a completely generic way that automatically handles undo and styling UI for prefabs.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

SerializedObject is used in conjunction with SerializedProperty and Editor classes.

// C# example: A custom Inspector for Transform components.
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Transform))]
public class TransformInspector : Editor {

SerializedObject m_Object;
SerializedProperty m_Property;

void OnEnable () {
m_Object = new SerializedObject (target);
m_Property = m_Object.FindProperty ("m_LocalPosition.x");
}

void OnInspectorGUI () {
// Grab the latest data from the object
m_Object.Update ();

// Editor UI for the property
EditorGUILayout.PropertyField (m_Property);

// Apply the property, handle undo
m_Object.ApplyModifiedProperties ();
}
}

Variables
targetObject

The inspected object (Read Only).

Constructors
SerializedObject

Create SerializedObject for inspected object.

Functions
Update

Update serialized object's representation.

GetIterator

Get the first serialized property.

FindProperty

Find serialized property by name.

ApplyModifiedProperties

Apply property modifications.

ApplyModifiedPropertiesMultiSelect

Apply modified properties using the current selection