FactorableDataUtility
Internal static utility class for creating deep and shallow copies of FactorableData records. Deep copy uses Odin binary serialization for a full value clone including nested references; shallow copy uses C# record with expressions.
Definition
Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll
internal static class FactorableDataUtilityRemarks
This utility is used internally by the factory system (specifically ScriptableFactory<TObject, TData>.Spawn()) to ensure each spawned object receives its own independent copy of data. This prevents mutations on one object from affecting others.
Deep copying is performed via Odin's SerializationUtility — the data is serialized to a binary MemoryStream then deserialized back into a new instance. This correctly handles:
Nested objects and complex reference graphs
Unity
Objectreferences (preserved via theunityObjectslist)Custom Odin-serialized types
Shallow copying uses the C# record with { } expression, which creates a memberwise clone (reference fields are shared, not cloned).
Quick Lookup
Deep copy data
FactorableDataUtility.CreateCopy(data)
Shallow copy data
FactorableDataUtility.CreateCopy(data, CopyMode.SHALLOW)
Null-safe copy
Returns null if input is null
Methods
CreateCopy<TData>
Creates a copy of the given data record.
data
TData
—
The data record to copy. Can be null.
copyMode
CopyMode
DEEP
Whether to perform a deep or shallow copy.
Returns: A new TData instance, or null if input was null.
Nested Types
CopyMode (enum)
SHALLOW
Uses C# record with { } — fast but shares nested references
DEEP
Uses Odin binary serialization — slower but fully independent clone
Common Pitfalls
Shallow copy shares nested references CopyMode.SHALLOW only clones top-level fields. Nested objects (lists, dictionaries, custom classes) will be shared between the original and the copy. Use DEEP when data contains mutable nested references.
Internal access only This class is internal. Game code should not call it directly — it is invoked automatically by the factory's Spawn() method. If you need to copy data in game code, access it through the factory API.
See Also
FactorableData — the abstract record base this utility copies
ScriptableFactoryRegistry — central registry of factories
Last updated