Item Upgrades
Build upgrades from Item Definitions, mutable attributes, nested upgrade Items or crafting. Choose one source of truth for the result and keep eligibility, payment, Item changes and UI refresh in one project-owned operation.
Choose a model
| Result | Model | Responsibility |
|---|---|---|
| Known tiers: Iron Sword → Iron Sword +1 | Parent/child definitions | Author each tier and its explicit next-tier link. |
| Independent levels/rolls | Mutable Item attributes | Calculate per-copy growth and present it. |
| Removable runes/gems | Nested ItemAmounts |
Adapt the demo’s slot UI and make transfers transactional. |
| Ingredient-driven upgrade menu | Crafting plus custom processor | Resolve the exact selected input and replacement. |
If combining models, specify one order for definition values, runtime level and slotted bonuses.
Definition tiers
Use the Item Definition editor with these data choices:
| Data | Example |
|---|---|
| Direct Item Category | Weapon on both Iron Sword and Iron Sword +1; parent/child definitions require the same direct category. |
| Parent | Iron Sword on Iron Sword +1. |
| Attack attribute | Integer on Weapon’s Item Definition attributes. Child Modify: <Inherited> + 2, or Override for a fixed value. |
Project Upgrade attribute |
Type ItemDefinition; Iron Sword points to Iron Sword +1. Final tier is empty, or another explicit next tier is assigned. |
| Requirements | Project data such as UpgradeGoldCost and RequiredLevel. |
Confirm the child appears below its parent and resolves Attack two points higher. Parent relationships supply inheritance; project logic reads the explicit upgrade link and owns direction, costs and replacement.
Exchange without losing ownership
- Start from the selected Item Info. Validate next definition, payment, level and full destination acceptance before mutation, accounting for the original leaving its slot.
- Create the replacement from the next definition. Copy any state that should survive, such as current Durability; its Default Item otherwise supplies starting values.
- Remove one original and add one replacement through the collection. For explicit returned-amount accounting, disable Return Overflow, inspect both results and handle every remainder.
- Charge only when exchange can complete, or restore Item and payment together on failure. Preserve a return path for the original.
- Assign the replacement Item Info to custom selection UI and redraw it; collection-driven views follow inventory notifications.
A definition-tier upgrade creates a new Item from a different definition. Use mutable attributes for changes to the existing Item’s identity.
Per-copy growth
Declare Level/Attack under Weapon’s Item attributes, make the category Mutable and Unique, and set initial values on the Definition’s Default Item. A custom action validates costs, calculates the next values and sets overrides on the selected runtime Item. Refresh cached gameplay/UI totals as well as bound Item Objects.
This allows one sword at level 7 and another at level 1 without authoring every tier. Save the owning Inventory and included mutable Item state; use explicit overrides for rollback-sensitive values.
Adapt the demo slots
Copy UpgradeMenu and ItemUpgradePanel into a project namespace before changing rules; they are demo samples.
| Contract | Sample choice |
|---|---|
| Upgradable Item data | Integer SlotCount and ItemAmounts Slots. |
| Panel references | Upgradable Item View, Upgrade Item View Slots, Upgrade Item Removers. |
| Panel attribute-name fields | Slot Count Attribute Name / Slots Attribute Name; empty fields use SlotCount / Slots. |
| Upgrade contribution | BoostConstant and BoostMultiplier. |
| Recomputed stats | Attack from BaseAttack; Defense from BaseDefense. |
Define category eligibility, validate removal/return and own rollback around each slot change. Preserve preview, redraw and Item-change callbacks in the adapted UI. Enable Using Nested Items on Inventory System Manager Item Saver, and keep saved nesting one level deep.
Crafting-based upgrades
Use a custom Crafting Processor when the result depends on the selected weapon, its attributes or material mix. Validate the exact selected Item Info, calculate/resolve its replacement and complete remove/add/payment with rollback. Derive from Simple Crafting Processor when its ordinary ingredient handling helps. Fixed recipe results suit ordinary crafting; custom input-state changes belong in the processor.
Verify upgrades
Test with two swords. Upgrade one and confirm the other keeps its definition/values. Equip/move the result and check restrictions plus name/icon/Attack display. Reject insufficient resources and full/restricting destinations with Item/payment unchanged. Save/restart/load and verify the upgraded state; for nested slots, remove/reinsert an upgrade and verify its stats and Item survive.
Troubleshooting
| Symptom | Check and fix |
|---|---|
| Parent rejected or Attack unchanged | Match direct categories and inspect the child’s Variant/expression. |
| Item/payment lost or another sword changes | Use selected-stack context, mutable/unique identity and a verified full exchange with rollback. |
| Stale selection | Assign returned replacement Item Info and redraw custom UI. |
| Missing nested upgrade after load | Enable nested Item saving and keep one saved level. |
| Recipe yields wrong weapon | Use a processor that resolves the exact selected input’s result. |
Developer reference
Author ItemDefinition.Parent/SetParent relationships in Main Manager; ChildrenReadOnly exposes them. Create tier replacements through InventorySystemManager.CreateItem(ItemDefinition, ...). Read resolved attributes with TryGetAttributeValue<T> and set mutable typed attributes with Attribute<T>.SetOverrideValue.
ItemCollection.CanAddItem, AddItem and RemoveItem use Item Info; check actual amounts and destination state. CraftingProcessor exposes ingredient selection, CanCraft, CanCraftInternal and CraftInternal. Keep shared upgrade rules in one service/action so menus and previews agree.
Related: Defining Attributes, Stats, Item Actions, Save System, Demo Scene.