FactorableData

Abstract record base class for all data attached to factory-spawned objects. Uses C# record semantics to enable value-based equality and built-in with expression support for shallow copying. Designed to be subclassed with game-specific fields.

Definition

Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll

[Serializable]
public abstract record FactorableData

Remarks

FactorableData is a C# record (reference type with value semantics), which provides:

  • Value equality — two data instances with the same field values are considered equal.

  • with expression support — enables shallow copying via data with { }, used by FactorableDataUtility.CreateCopy() in SHALLOW mode.

  • Immutability-friendly — records encourage immutable patterns, though fields can still be mutable for Unity serialization.

Data records are stored on ScriptableFactory<TObject, TData> assets and deep-copied before being applied to spawned objects (via FactorableDataUtility), ensuring each object instance gets its own data copy.

Fields marked with [Overridable] can be overridden per-variant or per-spawn through the DataOverride / DataVariantSystem without modifying the source data.

Quick Lookup

Goal
How

Define custom data

Subclass FactorableData with fields

Deep copy

FactorableDataUtility.CreateCopy(data)

Shallow copy

FactorableDataUtility.CreateCopy(data, CopyMode.SHALLOW)

Mark field as overridable

Apply [Overridable] attribute

Extension Points

Required Overrides

None. FactorableData has no abstract members — it serves as a marker base type.

Pattern: Defining Custom Data

Subclass and add serialized fields:

Implementation Requirements

When subclassing FactorableData, you MUST:

  1. Mark the class with [Serializable] for Unity/Odin serialization

  2. Use the record keyword (not class) to maintain copy semantics

You SHOULD:

  • Mark fields with [Overridable] if they should be customizable via DataOverride / variants

  • Use public fields or [OdinSerialize] for Inspector visibility

  • Keep fields simple and serializable (avoid non-serializable reference types)

Examples

Basic Data Record

Using Data with a Factorable Object

See Also

Last updated