SerializedProperty Extensions
Write values and access C# fields through SerializedProperty.
Quick start
| Before — Unity API | After — FastTools |
|---|---|
| |
Writing values
| Call | What it does |
|---|---|
SetInt(42) | Writes the value |
SetIntAndApply(42) | Writes the value and applies changes |
SetIntAndApplyWithoutUndo(42) | Writes the value and applies changes without Undo |
The SetValue overloads select a setter by argument type: SetValue(42) calls SetInt. The argument type must match the field type. Integer types narrower than int, and char, also call SetInt. See the API reference for the full list of setters.
Enums, arrays and references
| Unity | FastTools |
|---|---|
intValue = (int)Rarity.Rare | SetEnum(Rarity.Rare) |
enumValueIndex = 1 | SetEnumIndex(1) |
enumValueFlag = flags | SetEnumFlag(flags) |
arraySize = 5 | SetArraySize(5) |
arraySize++ | AddArraySize() |
arraySize-- | RemoveArraySize() |
managedReferenceValue = value | SetManagedReference(value) |
objectReferenceValue = value | SetObjectReference(value) |
boxedValue = value | SetBoxed(value) |
exposedReferenceValue = value | SetExposedReference(value) |
SetEnumIndexandSetEnumFlaghave noSetValueform: call them by name.SetValue(1)on an enum field callsSetInt: it writes the value 1, not the index.SetEnumandSetValue(Rarity.Rare)write the enum value.
With an IExposedPropertyTable context, such as a PlayableDirector, SetExposedReference() stores the reference in the table at once, but the new name stays pending. Call ApplyModifiedProperties() after it: otherwise the next update or a domain reload discards the name and leaves an orphan entry in the table.
Update() and Apply…()
These methods are called on the property and, like setters, return it for chaining.
| Unity | FastTools |
|---|---|
serializedObject.Update() | Update() |
serializedObject.UpdateIfRequiredOrScript() | UpdateIfRequiredOrScript() |
serializedObject.ApplyModifiedProperties() | ApplyModifiedProperties() |
serializedObject.ApplyModifiedPropertiesWithoutUndo() | ApplyModifiedPropertiesWithoutUndo() |
Accessing the C# field
The methods return the field type, its FieldInfo and the owning object.
public class AbilityBook : MonoBehaviour
{
[SerializeField]
private List<Ability> _abilities = new() { new Ability() };
[SerializeReference]
private IAbilityEffect _effect = new BurnEffect();
}
[Serializable]
public class Ability { public string Name = "Fireball"; }
[Serializable]
public class BurnEffect : IAbilityEffect { public float Damage = 5f; }
| Field / element | GetPropertyType() | GetFieldInfo() | GetDeclaringInstance() |
|---|---|---|---|
_abilities | List<Ability> | AbilityBook._abilities | the AbilityBook |
_abilities[0] | Ability | AbilityBook._abilities | the AbilityBook |
_abilities[0].Name | string | Ability.Name | the Ability at index 0 |
_effect | IAbilityEffect | AbilityBook._effect | the AbilityBook |
_effect.Damage | float | BurnEffect.Damage | the BurnEffect instance |
- if the field is not found,
GetPropertyType()andGetFieldInfo()returnnull, andGetDeclaringInstance()does only when the owning object is not found; - the methods read only the first target object and only applied values.
When the field's owner is a struct, GetDeclaringInstance() returns a boxed copy. Changes to that copy never reach the original; write values through the SerializedProperty instead.
Member name and drawing checks
| Field / element | GetMemberName() | IsArrayElement() | HasFoldout() |
|---|---|---|---|
_abilities[0] | "_abilities" | true | true |
_abilities[0].Name | "Name" | false | false |
_effect | "_effect" | false | false |
HasFoldout() checks ordinary compound fields with visible children. It does not account for [SerializeReference] or custom PropertyDrawers.
Persistent()
Persistent() returns a copy of the property on its own SerializedObject, so it can be used later, for example in EditorApplication.delayCall.
- the copy belongs to the caller: dispose it together with its
serializedObject; - unapplied writes of the source property do not reach the copy;
- if the property is missing on the targets, the method returns
null.
var independent = manaCost.Persistent();
if (independent == null) return;
EditorApplication.delayCall += () =>
{
using (independent.serializedObject)
using (independent)
independent.Update().SetIntAndApply(42);
};
Package sample
In EditorTools, the Reset to defaults button writes two properties with SetFloat and SetIntAndApply.

