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 : FactorableDataRemarks
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
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
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.
dataOverride
DataOverride
The variant override definition to add
RemoveDataOverride
Removes a variant definition by reference. Invalidates the bake cache.
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.
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.
variantIndex
int
Zero-based variant index
Returns: The baked TData variant instance.
Index out of range
No bounds checking is performed. Accessing an index beyond Count - 1 will throw an ArgumentOutOfRangeException.
GetAllDataVariants
Returns all baked variant instances. Auto-bakes if not already baked.
Baking Lifecycle
Common Pitfalls
Variants are index-based, not identity-based Removing a variant shifts all subsequent indices. Code that caches variant indices should be aware that indices may change after removal.
Baked variants are cached copies
Each baked variant is a deep copy of the source data with overrides applied. Modifying a baked variant does not affect the source data or other variants, but the modification will be lost on the next Bake().
No bounds checking on GetDataVariant
GetDataVariant() accesses the internal list directly. Passing an out-of-range index throws ArgumentOutOfRangeException. Always check Count first.
See Also
DataOverride — individual variant definition applied during baking
FactorableData — base record type for source data
FactorableDataUtility —
CreateCopy()used during bakingScriptableFactory<TObject, TData> — factory that owns this variant system
Last updated