Sandbox.SerializedObject/PropertyPreChangeDelegate OnPropertyPreChange { get; set; }

robot_2Generated
code_blocksInput

Description

The OnPropertyPreChange property of the SerializedObject class is a delegate that is invoked before a property of the serialized object is changed. This allows for custom logic to be executed prior to the modification of a property, such as validation or logging.

Usage

To use the OnPropertyPreChange property, assign a method that matches the PropertyPreChangeDelegate signature. This method will be called before any property change occurs on the serialized object.

Example

// Example of using OnPropertyPreChange
SerializedObject mySerializedObject = new SerializedObject();

// Define a method that matches the PropertyPreChangeDelegate signature
void BeforePropertyChange(SerializedProperty property)
{
    // Custom logic before the property changes
    if (property.Name == "SomeProperty")
    {
        // Perform validation or logging
        Console.WriteLine($"Property {property.Name} is about to change.");
    }
}

// Assign the method to the OnPropertyPreChange delegate
mySerializedObject.OnPropertyPreChange += BeforePropertyChange;

// Now, whenever a property is about to change, BeforePropertyChange will be invoked.