Class SerializedPropertyExtensions
Extension methods for UnityEditor.SerializedProperty that provide reflection-based access to the underlying C# objects and fields serialized by Unity.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
public static class SerializedPropertyExtensions
Remarks
Unity's UnityEditor.SerializedProperty API exposes property values through
type-specific accessors (e.g. intValue, stringValue), but gives no
direct way to obtain the underlying boxed object or its
FieldInfo. These extension methods fill that gap
by traversing the serialized property path via reflection and caching the resulting
field lookups for improved Editor performance.
Results are cached in _fieldCache (keyed by type and field name) so that
the cost of reflection is paid at most once per unique (type, field-name) pair
within a single Editor session.
Methods
GetFieldInfo(SerializedProperty)
Returns the FieldInfo that corresponds to property
on its containing object. This is useful for reading custom attributes attached to
the field declaration in property drawers, where fieldInfo may be unavailable.
Declaration
public static FieldInfo GetFieldInfo(this SerializedProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The UnityEditor.SerializedProperty whose backing FieldInfo is
required. If |
Returns
| Type | Description |
|---|---|
| FieldInfo | The FieldInfo for the field named |
GetSiblingProperty(SerializedProperty, string)
Returns a UnityEditor.SerializedProperty that shares the same parent scope as
property and has the field name siblingName.
This is useful in property drawers that need to read a companion field on the same
object - for example, reading a _condition field while drawing a field
decorated with [ShowIf(nameof(_condition))].
Declaration
public static SerializedProperty GetSiblingProperty(this SerializedProperty property, string siblingName)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The reference UnityEditor.SerializedProperty whose parent path is used to locate the sibling. |
| string | siblingName | The serialized field name of the desired sibling property, relative to the same parent. |
Returns
| Type | Description |
|---|---|
| SerializedProperty | A UnityEditor.SerializedProperty for the sibling field, or |
GetTargetObject(SerializedProperty)
Returns the C# object that directly contains the field represented by
property. For a top-level property this is the
targetObject of the UnityEditor.SerializedObject; for nested or array
properties the method walks the property path via reflection to reach the correct
intermediate object.
Declaration
public static object GetTargetObject(this SerializedProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The UnityEditor.SerializedProperty whose containing object is required. If
|
Returns
| Type | Description |
|---|---|
| object | The C# object that holds the field described by |
Remarks
The property path is normalized by replacing .Array.data[n] with [n]
before splitting on periods. Array and list indexers are resolved by
retrieving the element at the given index from the underlying collection field.
GetValue(SerializedProperty)
Returns the boxed runtime value of property by first resolving the
containing object via GetTargetObject(SerializedProperty) and then reading the field value
using reflection. This works for any serializable field type, including custom structs
and classes, unlike Unity's type-specific accessors.
Declaration
public static object GetValue(this SerializedProperty property)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializedProperty | property | The UnityEditor.SerializedProperty whose value should be read. If |
Returns
| Type | Description |
|---|---|
| object | The boxed value of the underlying field, or |