Skip to content

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).
  • RecipeDefinition is an authoring helper that resolves into RecipeCore when the Inventory integration is present.
  • Conversion and caching behaviour are intentionally hidden behind the public RecipeResolve API.
  • Projects may ship with no RecipeDefinition assets 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.item may be temporarily null during editing.
  • OnValidate() trims obvious strings and clamps obvious numeric fields.
  • IsValid is 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 ItemRef entries using ItemDefinition.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 RecipeCore is treated as a runtime-only object (not saved)

ToCore() always allocates a new RecipeCore instance 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 asset is a RecipeCore, it is returned directly
  • If asset is 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

  1. Create a RecipeDefinition via: Assets → Create → RevFramework → Crafting → Recipe (Unity)
  2. Add inputs and outputs using ItemDefinition assets
  3. Optionally configure:

  4. currency ID and cost

  5. craft time
  6. station tag
  7. display name and description
  8. At runtime, resolve with:

RecipeResolve.TryResolve(asset, out var core);
5. Pass the resulting RecipeCore into Crafting APIs


Notes

  • RecipeDefinition compiles only when REV_INVENTORY_PRESENT is defined
  • Resolution of this wrapper is registered at runtime through the RecipeResolve pipeline
  • Other wrappers (sample or custom) may also participate in resolution when registered
  • Converted recipes are runtime-created objects (not saved) and contain no ItemDefinition references

RecipeDefinition exists purely to support Unity authoring. The Crafting runtime consumes RecipeCore data.