Skip to content

Inventories

Craftwright doesn’t own your inventory. Crafters and stations count, take and give items through one interface, Craftwright Inventory (ITACraftwrightInventory). Anything that implements it, an actor or a component, written in Blueprint or C++, can hold ingredients, receive results and burn as station fuel.

You have three options:

  • Use the built-in inventory component, for projects without an inventory, for station fuel and chests, and for testing.
  • Write an adapter for your own inventory, in Blueprint or C++.
  • Start from the Lyra adapter template for the Lyra Starter Game.
Function Meaning
Get Item Count (Item) How many of the item the inventory holds. Used when ingredients are taken and for station fuel.
Get Items (Out Items) Everything the inventory holds that maps to Craftwright items, as item stacks. Every ingredient check uses it: Check Craft, “how many can be made”, tag ingredients, the menu’s “have” counts and discovery. An item missing here can’t be used as an ingredient.
Remove Items (Item, Count) Remove up to Count; return how many were removed. Only called on the server.
Add Items (Item, Count) Add up to Count; return how many were added. Only called on the server.
Get Room For (Item) How many more of the item fit. Return a large number when there is no limit.

Rules for an implementation:

  • Return what really happened. Craftwright clamps the results to 0 .. Count and relies on them: when a removal comes up short, the craft is rolled back and everything already removed is added back.
  • Get Items should report only items that map to Craftwright items, merged per item, with counts above 0.
  • Get Item Count and Get Items are also called on clients, for the menu. They should work on whatever your inventory replicates to the owning client.
  • Get Room For decides how many results are put into the inventory; the rest goes to the next inventory or into the tray.

Craftwright Inventory (UTACraftwrightInventoryComponent) is a small replicated inventory. Items stack per type: one entry per item with its count.

Property Default Meaning
Slots 0 The number of stacks that fit; each holds up to the item’s Max Stack. 0 = no limit.
Starting Items Empty Items given on the server at Begin Play.
Share With Nearby Crafting Off Lets stations and crafters within their pull radius take ingredients from this inventory: chests, storage boxes.
Owner Only Off Replicate the contents only to the owning player (player inventories). Off = everyone sees them (chests, stations). On Unreal Engine 5.0 to 5.2 the class default counts: set it in a Blueprint or C++ subclass, or use Craftwright Player Inventory.
Function or event Meaning
Get Entries The contents, one entry (Item, Count) per item type
Clear Items Server only: removes everything
Export Save Data, Import Save Data The contents as a save struct. See Save games.
On Inventory Changed Fires on the server and on clients whenever the contents change

C++ code can also call CountOf, Add, Remove and RoomFor directly.

How slots are counted: every item uses as many slots as its count needs (ceil(count / Max Stack)). The room for an item is the free slots × its Max Stack, plus what fits on its last partly filled stack. With 30 slots, 50 Oak Logs (Max Stack 50) use one slot; the 51st needs a second.

The contents replicate with a fast array: only changed entries are sent. Owner Only limits them to the owning connection, so other players don’t receive your bag.

Craftwright Player Inventory (UTACraftwrightPlayerInventoryComponent) is the built-in inventory with Owner Only on, for players: only the owning player receives its contents on every engine version.

In the example, the player’s inventory is a Craftwright Player Inventory with 30 slots, each station has a 6-slot inventory, and the Ore Chest has no slot limit and Share With Nearby Crafting on.

An adapter is a component that implements the interface by calling your inventory. Put it next to your inventory, on an actor where the crafter looks for inventories (see Inventory sources), and map your items to Craftwright items.

  1. Create a Blueprint class with Actor Component as parent, for example BP_CraftwrightAdapter.

  2. Open Class Settings, and under Implemented Interfaces add Craftwright Inventory.

  3. Implement the five functions in My Blueprint > Interfaces by calling your inventory:

    • Get Item Count: look up the item in your inventory (see Mapping your items) and return its count.
    • Get Items: loop over your inventory, call Find Item For External for each of your items, and add a stack (Item, Count) for each match, merged per item.
    • Remove Items, Add Items: change your inventory and return how many were removed or added.
    • Get Room For: return how many more fit, or a large number such as 1000000.
  4. Add the component to the actor that holds your inventory, for example the Player Controller or the Pawn.

  5. After your inventory changes on the server, call Notify Inventory Changed on the crafter if you use discovered recipes.

Each Craftwright Item has three Adapter fields that say which of your items it stands for. Use whichever fits your inventory:

Field Use it when your items are
External Class Classes, for example item definition Blueprints (Lyra’s ID_... definitions)
External Asset Assets, for example item data assets
External Id Ids or data table row names

Going from a Craftwright item to yours is a property read (Item->ExternalId, External Class, External Asset). Going back, for Get Items, use Find Item For External (External, Id) from the library UTACraftwrightLibrary:

  • pass your item’s class or asset as External, or your id as Id;
  • it returns the Craftwright item whose External Class or External Asset is that object, or whose External Id is that id, and none when no item maps to it.

The lookup is built from the Asset Registry: the first call loads every Craftwright item once. When an item isn’t found, the lookup is rebuilt, at most once a second, so items created while the game runs are found too.

Built-in inventories tell the crafter when they change, so discovered recipes are learned right away. Your own inventory doesn’t: call Notify Inventory Changed on the crafter, on the server, after its contents change.

The plugin’s Docs/Adapters/Lyra folder contains an adapter component for the Lyra Starter Game’s inventory (ULyraInventoryManagerComponent), as source to copy into a Lyra project. It isn’t compiled with the plugin.

  1. Copy TACraftwrightLyraInventoryAdapter.h and TACraftwrightLyraInventoryAdapter.cpp into LyraGame/Inventory/ in your Lyra project.

  2. Add "TACraftwright" to PublicDependencyModuleNames in LyraGame.Build.cs.

  3. Add the Craftwright Lyra Inventory Adapter component to the player controller, next to the Lyra inventory. Its Inventory property can point at a Lyra inventory; when empty, it uses the one on its owner.

  4. For each Craftwright Item, set External Class to the Lyra item definition (ID_...).

  5. Add a Craftwright Crafter to the player controller too, and build.

Lyra counts every item instance as one item, so the adapter does too: a stack of 5 in Lyra’s sense is 5 instances. It removes items one at a time and reports no capacity limit for items it knows.

A crafter finds its inventories by itself, and you can add more.

Setting or function Meaning
Auto Find Inventories (default on) Use inventories on the crafter’s owner and, depending on the owner, its pawn, controller and player state. A crafter on the Player Controller finds a bag on the Pawn and the Player State.
Add Inventory Source, Remove Inventory Source Add any inventory (an actor or component that implements the interface) to take ingredients from, for example a backpack actor or a vehicle’s trunk.
Set Output Inventory, Get Output Inventory Where results go first. By default the first of the crafter’s own inventories.
Nearby Container Radius (default 0, off) Also take ingredients from shared containers within this distance of the crafter.
Register Shared Inventory, Unregister Shared Inventory (library) Make any inventory, for example another plugin’s chest, available to crafters and stations within their radius. The built-in inventory does this itself with Share With Nearby Crafting.
Get Ingredient Sources (Station) Every inventory a craft would use, in order.

See Where ingredients come from for the order, and Outputs and the tray for where results go.