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 FactorableDataUtility

Remarks

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 Object references (preserved via the unityObjects list)

  • 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

Goal
How

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.

Parameter
Type
Default
Description

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)

Value
Description

SHALLOW

Uses C# record with { } — fast but shares nested references

DEEP

Uses Odin binary serialization — slower but fully independent clone

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

Last updated