DataVariantSystem

Manages a source FactorableData instance and a list of DataOverride definitions, producing baked variant instances on demand. Supports lazy baking — variants are computed when first requested and cached until invalidated.

Definition

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

[Serializable]
public class DataVariantSystem<TData> where TData : FactorableData

Remarks

DataVariantSystem is the top-level coordinator of the variant pipeline. It is owned by ScriptableFactory<TObject, TData> and manages the factory's data variants.

The system maintains two parallel lists:

  • dataOverrides — the variant definitions (serialized, editable in Inspector)

  • dataVariants — the baked results (transient, rebuilt from overrides + source data)

Baking is lazy: calling GetDataVariant() or GetAllDataVariants() auto-bakes if the system is not yet baked. Any mutation to the override list (add/remove) sets baked = false, triggering a re-bake on next access.

Quick Lookup

Goal
How

Get variant count

system.Count

Get one variant

system.GetDataVariant(index)

Get all variants

system.GetAllDataVariants()

Add a variant

system.AddDataOverride(dataOverride)

Remove a variant

system.RemoveDataOverride(dataOverride)

Remove by index

system.RemoveDataOverrideAt(index)

Force rebuild

system.Bake()

Invalidate cache

system.ClearBake()

Properties

Count

Number of variant definitions (DataOverride instances).

Constructor

Parameter
Type
Description

sourceData

TData

The base data that all variants derive from

Initializes with empty override and variant lists, baked = false.

Methods

AddDataOverride

Adds a new variant definition. Invalidates the bake cache.

Parameter
Type
Description

dataOverride

DataOverride

The variant override definition to add

RemoveDataOverride

Removes a variant definition by reference. Invalidates the bake cache.

Parameter
Type
Description

dataOverride

DataOverride

The variant override definition to remove

Returns: true if the override was found and removed.

RemoveDataOverrideAt

Removes a variant definition by index. Invalidates the bake cache.

Parameter
Type
Description

index

int

Zero-based index of the variant to remove

Bake

Rebuilds all variant instances by applying each DataOverride to a copy of the source data. Clears any previously baked variants and sets baked = true.

Each override produces one variant via dataOverride.Apply(sourceData), which internally creates a deep copy of the source data before applying field modifications.

ClearBake

Clears the cached variant list and sets baked = false. The next access to GetDataVariant() or GetAllDataVariants() will trigger a re-bake.

GetDataVariant

Returns the baked variant at the given index. Auto-bakes if not already baked.

Parameter
Type
Description

variantIndex

int

Zero-based variant index

Returns: The baked TData variant instance.

circle-exclamation

GetAllDataVariants

Returns all baked variant instances. Auto-bakes if not already baked.

Baking Lifecycle

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

  • DataOverride — individual variant definition applied during baking

  • FactorableData — base record type for source data

  • FactorableDataUtilityCreateCopy() used during baking

  • ScriptableFactory<TObject, TData> — factory that owns this variant system

Last updated