# OnBeforeSerialize()

> Implement this callback to transform data into serializable data types immediately before an object is serialized.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/7000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
void OnBeforeSerialize()
```

### Remarks

Unity invokes the `OnBeforeSerialize` callback on an object before serializing it. In this callback, you can transform your data into something Unity understands.

Refer to [Custom serialization](/engine/7000.0/manual/programming-environment/code-reload-serialization/script-serialization/custom-serialization.md) in the Manual for more information.

**Note:** Unity calls `OnBeforeSerialize` before recompiling scripts in a domain reload, so any changes made to code in this method won't take effect until the second invocation of the callback following the change, in other words after a full serialization and domain reload cycle. For more information, refer to [Details of disabling domain and scene reload](/engine/7000.0/manual/programming-environment/code-reload-serialization/code-reload/code-reloading-editor/configurable-enter-play-mode-details.md) in the Manual.
