Game.Serialization.IPostDeserialize
Assembly: Game
Namespace: Game.Serialization
Type: Interface
Base: N/A
Summary:
IPostDeserialize is an interface used by the game's serialization system to notify objects after they have been deserialized. Implementers should use the PostDeserialize method to restore transient state, re-establish runtime-only references, perform validation, or register the object with runtime systems that are not handled by the raw serialization process. The Context parameter provides contextual information from the serializer (from Colossal.Serialization.Entities).
Fields
None
IPostDeserialize is an interface and does not declare fields. Implementing types may have their own fields that require post-deserialization setup.
Properties
None
The interface itself does not define properties. Implementers may expose properties as needed.
Constructors
None
Interfaces do not have constructors. Concrete implementing types will provide their own constructors and initialization logic.
Methods
void PostDeserialize(Colossal.Serialization.Entities.Context context)
Called by the serialization framework after an object has been deserialized. Use this method to:- Reinitialize transient or non-serializable members (timers, event subscriptions, cached handles).
- Resolve or re-link references that require runtime context (lookups in registries, caches, or scene objects).
- Validate deserialized data and apply any necessary corrective transformations.
- Register the object with game systems that expect runtime-only registration.
Parameters:
- context
— Serialization context provided by Colossal.Serialization.Entities. It may contain helper methods, lookup tables, or state used by the serializer to assist in post-deserialization work.
Usage Example
using Colossal.Serialization.Entities;
using Game.Serialization;
public class MySerializableComponent : IPostDeserialize
{
// Serializable fields
public int id;
public string name;
// Transient runtime-only field (not serialized or needs reinit)
private SomeRuntimeHandle runtimeHandle;
public void PostDeserialize(Context context)
{
// Rebuild or acquire runtime-only resources
runtimeHandle = RuntimeHandleRegistry.GetHandle(id);
// Optionally validate or fix data
if (string.IsNullOrEmpty(name))
{
name = "Unnamed";
}
// Register with a runtime system that isn't handled by the serializer
SomeRuntimeSystem.Register(this);
}
}
Notes: - The serializer will call PostDeserialize after constructing the object and populating serializable fields. Do not rely on other external objects being fully initialized unless you know the serializer's ordering guarantees. - Keep PostDeserialize implementations idempotent where possible, as they may be called in different contexts (e.g., reloads, incremental deserialization).