Make a consumable item¶
Designer · 45 min · No code
Result: an item, Mend Salve, that the party carries in the bag. Using it spends one and restores the leader's HP.
Read this first: what the template does and does not do
XenoCore has no "use item" command in the menu today. The Items menu lists, sorts and describes items, and nothing in it spends one. Items are spent by quests (turn-in), by shops and trades, and by your own abilities.
This recipe therefore builds the item and a gameplay ability that uses it. You trigger the ability with an input or from another graph. A menu entry that calls it is a UI job; see Add a menu screen.
Before you start¶
- Add a weapon: item definitions and fragments.
- Items and inventory: one bag entry is one item.
How it is put together¶
| Piece | You make | Based on |
|---|---|---|
| The item | ID_MyGame_MendSalve |
A shipped item from Inventory/Items |
| The heal | GE_MyGame_Mend |
Lyra's /Game/Environments/Gameplay/GE_GameplayEffectPad_Heal |
| The use | GA_MyGame_UseMendSalve |
A new Lyra Gameplay Ability |
The ability carries a Party Item (XenoCore) cost: it cannot activate unless the party holds a Mend Salve nobody is wearing, and committing the ability spends one. The cost does the bag work through XenoCore's inventory functions, which find the party's bag for you and tell every open screen that the bag changed.
Steps¶
1. Make the item¶
- Create a
MyGame/Itemsfolder under Content. - In Plugins › XenoCore Content › Inventory › Items, right-click
ID_XenoCore_CoolPotato, choose Duplicate, move the copy intoMyGame/Itemsand name itID_MyGame_MendSalve. Never create an item definition from blank. - Open it. In Class Defaults, set Display Name to
Mend Salve. - Expand Fragments. In the Xeno Core Fragment Item Category entry, under
XenoCore › Item, leave Category on
Collectables(the potato's), and set Max Carried to20and Sell Value. Max Carried is the most the party may hold;0means no limit. Do not pickItems: no Items-menu tab lists that category, so the salve would be carried but never shown. - In the Xeno Core Fragment Item Display entry, set Description and Icon.
- Make sure there is no Xeno Core Fragment Equip Slots entry, or the item becomes equipment.
- Click Compile, then Save.
2. Make the heal¶
- In the Content Browser, open
Content/Environments/Gameplay(Lyra's own content), right-clickGE_GameplayEffectPad_Heal, choose Duplicate, move the copy intoMyGame/Itemsand name itGE_MyGame_Mend. - Open it. The heal amount is on its execution, not a modifier: under Executions, in the
Lyra Heal Execution entry's Calculation Modifiers, set the BaseHeal modifier's
scalable float. Keep its Gameplay Cues entry
(
GameplayCue.Character.Heal): that is the heal effect you see. - Click Save.
3. Make the ability¶
- In
MyGame/Items, right-click and choose Blueprint Class. Under All Classes, pickLyraGameplayAbility. Name itGA_MyGame_UseMendSalve. - Open it. In Class Defaults, set Instancing Policy to Instanced Per Actor and leave Activation Policy on On Input Triggered.
- Under Costs, click + beside Additional Costs and choose Party Item (XenoCore) from the entry's class dropdown.
- In that entry, under XenoCore › Cost, set Item Definition to
ID_MyGame_MendSalveand Quantity to1. - In the event graph, build this chain from Event ActivateAbility:
- Commit Ability. This spends the Mend Salve. Branch on its return value; on False, End Ability and stop.
- On True: Apply Gameplay Effect to Owner, Gameplay Effect Class
GE_MyGame_Mend. - End Ability.
- Click Compile, then Save.
With an empty bag the ability does not activate at all, because the cost is checked before activation.
Without a cost
To spend items from a graph instead, use Consume Items From Party (XenoCore › Inventory) with Item Def and Count. It spends exactly that many or nothing, returns false when there are not enough, and never takes an item someone is wearing. Get Free Party Item Count tells you beforehand how many can be spent.
Fails silently: do not use Lyra's Inventory Item cost
The cost list also offers Lyra's own Inventory Item cost, and it looks like the same thing. In stock Lyra 5.8 its code is compiled out: its check always fails, so an ability carrying it can never activate, with nothing logged. Use Party Item (XenoCore).
Fails silently: spend items with the XenoCore nodes
Lyra's own inventory functions also remove items. XenoCore notices and still updates open screens and quest counters, but Lyra's removal functions can take an item a character is wearing, which then vanishes from the save. Use Consume Items From Party or Remove Item Instance From Party (both under XenoCore › Inventory).
4. Give the party some to use¶
- Open a pawn in the starting party, for example Kael,
Characters/VRoid/Kael/B_XenoCore_Party_VRoid_L. - In the Components panel, select its equipment component.
- In the Details panel, under XenoCore › Equipment, click + beside Starting Inventory.
- In the new entry, set Item Definition to
ID_MyGame_MendSalveand Count to3. - Click Compile, then Save.
Fails silently: a pawn that never spawns
Starting Inventory reaches the bag only when that pawn is spawned. A member who is not in
the party's Starting Roster (on Characters/Party/BP_XenoCore_Party), such as the colour
mannequins in Characters/Party, or B_XenoCore_Player, never spawns at New Game, so their
list is ignored with nothing logged. The shipped roster starts with Kael and Mira.
5. Grant the ability¶
For a first test, grant it from the console (step 3 of Test it). To keep it:
- Open
Characters/Party/AbilitySet_XenoCore_PartyMember. Every VRoid member is granted it, throughCharacters/VRoid/PawnData_XenoCore_Party_VRoid. - Click + beside Granted Gameplay Abilities.
- In the new entry, set Ability to
GA_MyGame_UseMendSalve. - Set Input Tag to a gameplay tag your input config maps to a key. See Input and camera and Add an input action prompt.
- Click Save.
Test it¶
- Open
Maps/L_XenoCore_Gymand press Play. - Let a minion hit you so you are below full HP.
- Open the console and enter
AbilitySystem.Ability.Grant GA_MyGame_UseMendSalve, thenAbilitySystem.Ability.Activate GA_MyGame_UseMendSalve. - The leader heals. Open the menu's Collectables tab: the party now holds two Mend Salves.
- Activate it three more times. The fourth use does nothing: with the bag empty the cost check fails and the ability does not activate.
If it doesn't work¶
| Symptom | Fix |
|---|---|
| The ability activates but nothing heals | The heal effect has no amount, or its cue was removed. Test the effect alone with AbilitySystem.Effect.Apply GE_MyGame_Mend. |
| The ability never activates | The cost's Item Definition is a different item from the one in Starting Inventory; both must be ID_MyGame_MendSalve. Also check that the cost is Party Item (XenoCore), not Lyra's Inventory Item (see the warning above). |
| The count never goes down | The graph does not call Commit Ability. The cost is only paid on commit. |
| The bag has no Mend Salves at New Game | The pawn you gave Starting Inventory to never spawns (see the warning in step 4). |
Going further¶
- Items and inventory.
- Build a drop table to have enemies drop it.
- Open a shop to sell it.