Crafting — Unity / RecipeDefinition¶
This folder contains the Unity-facing recipe asset (RecipeDefinition). It exists to support designer-friendly authoring in the Unity Inspector and is not part of the supported Crafting Core runtime API.
RecipeDefinition is a framework-provided authoring helper that compiles only when the relevant optional systems are present.
At runtime, Unity-facing recipe assets are resolved into RecipeCore data before being used by the Crafting service.
Truth-pass note: This README describes behaviour implemented by the current runtime and conversion helpers. Where behaviour depends on optional systems or registered converters, that dependency is stated explicitly.
Purpose¶
RecipeDefinition allows designers to author recipes using ItemDefinition assets instead of typing GUID strings manually.
Key points:
- The Crafting service operates on
RecipeCore(GUIDs + quantities + optional currency cost). RecipeDefinitionis an authoring helper that resolves intoRecipeCorewhen the Inventory integration is present.- Conversion and caching behaviour are intentionally hidden behind the public
RecipeResolveAPI. -
Projects may ship with no
RecipeDefinitionassets at all and rely on: -
RecipeCore - sample wrappers
- or custom authoring pipelines
RecipeDefinition structure (overview)¶
RecipeDefinition stores item references (ItemDefinition) plus authoring metadata (display name, description, station tag, currency fields, craft time).
Authoring notes (Editor-time):
Ingredient.item/Output.itemmay be temporarily null during editing.OnValidate()trims obvious strings and clamps obvious numeric fields.IsValidis a basic sanity check intended for tooling/debug, not a full runtime guarantee.
Conversion to RecipeCore¶
RecipeDefinition.ToCore() produces a new RecipeCore instance containing only runtime data:
- Inputs/outputs are converted to
ItemRefentries usingItemDefinition.guid - Quantities are clamped to at least 1
- Currency ID is trimmed/null-normalised; currency amount is clamped to non-negative
- Craft time is clamped to non-negative
- Station tag and strings are trimmed/null-normalised
- The created
RecipeCoreis treated as a runtime-only object (not saved)
ToCore()always allocates a newRecipeCoreinstance and performs no caching.
Supported runtime resolution (public API)¶
External runtime code should not call ToCore() or internal caches directly.
Use the supported seam:
bool ok = RecipeResolve.TryResolve(asset, out RecipeCore core);
Runtime behaviour:
- If
assetis aRecipeCore, it is returned directly -
If
assetis a convertible wrapper (e.g.,RecipeDefinition), conversion is attempted via: -
optional integrations
- registered external converters (see
RecipeResolve.RegisterExternalConverter(...)) - If conversion is unavailable, resolution fails gracefully (
false/null) without throwing
This keeps callers insulated from:
- optional integrations
- registered wrapper implementations
- internal caching details
- allocation mechanics
Internal caching (framework only)¶
When conversion is available, the framework may cache converted RecipeCore instances to avoid repeated allocations.
Current implementation notes:
- Cached cores are keyed by the source Unity asset
- Cached cores are marked
HideFlags.DontSave - Cache lifetime is an internal detail (e.g., cleared on domain reload)
This mechanism is not a supported extension point.
Validity & guardrails¶
RecipeDefinition.IsValid performs a basic sanity check for tooling/debug:
- At least one input and one output entry
- Non-null items have quantities >= 1
- Currency cost is non-negative
Editor-time guardrails in OnValidate():
- clamps negative cost/time
- fixes quantities < 1
- trims station tags, names, descriptions, and currency IDs
- allows placeholder null items during authoring
Typical workflow¶
- Create a
RecipeDefinitionvia: Assets → Create → RevFramework → Crafting → Recipe (Unity) - Add inputs and outputs using
ItemDefinitionassets -
Optionally configure:
-
currency ID and cost
- craft time
- station tag
- display name and description
- At runtime, resolve with:
RecipeResolve.TryResolve(asset, out var core);
RecipeCore into Crafting APIs Notes¶
RecipeDefinitioncompiles only whenREV_INVENTORY_PRESENTis defined- Resolution of this wrapper is registered at runtime through the
RecipeResolvepipeline - Other wrappers (sample or custom) may also participate in resolution when registered
- Converted recipes are runtime-created objects (not saved) and contain no
ItemDefinitionreferences
RecipeDefinition exists purely to support Unity authoring. The Crafting runtime consumes RecipeCore data.