Game.Serialization.IPreDeserialize
Assembly: Assembly-CSharp.dll
Namespace: Game.Serialization
Type: interface
Base: (none)
Summary:
Defines a simple pre-deserialization hook. Types that implement IPreDeserialize receive a call to PreDeserialize(Context) before the serializer populates their fields. Use this to reset transient state, allocate or clear collections, register the object with managers, or perform lightweight migration/setup steps that must occur before field data is applied. The Context parameter (from Colossal.Serialization.Entities) provides serialization metadata and helpers (object reference resolution, versioning or custom serializer services).
Fields
- (none)
Implementers should not expect any fields declared by the interface. Use PreDeserialize to prepare instance fields as needed prior to deserialization.
Properties
- (none)
The interface does not declare any properties.
Constructors
- (none)
Interfaces do not define constructors. Initialization logic that must run before deserialization should be placed in PreDeserialize.
Methods
void PreDeserialize(Context context)
Called by the serializer on objects that implement IPreDeserialize before the object's fields are deserialized. Typical responsibilities:- Reset or initialize transient fields and caches.
- Allocate collections (List/Dictionary) so the serializer can populate them.
- Register the instance with game systems/managers if needed prior to field population.
- Perform lightweight migration based on context-provided version/metadata. Notes and guidance:
- Keep the method fast and deterministic — it runs during the deserialization pipeline.
- Prefer not to perform heavy UnityEngine operations that require main-thread-only resources unless you are certain the call occurs on the main thread.
- Use Context helpers to inspect serialization metadata or resolve references when necessary.
Usage Example
using Colossal.Serialization.Entities;
using Game.Serialization;
using System.Collections.Generic;
public class MySerializableData : IPreDeserialize
{
// transient cache that should be reset before deserialization
private List<int> _tempCache;
public void PreDeserialize(Context context)
{
// Prepare transient fields so the serializer can populate or rely on them
_tempCache = new List<int>();
// Example: read metadata (pseudo-code; actual API depends on Context implementation)
// if (context.TryGetMetadata("dataVersion", out int version)) { /* migrate if needed */ }
}
// ... other serialization members (fields/properties) ...
}