How-To: Add Context Actions
Goal: give items a right-click menu (Use, Drop, Equip...).
Prerequisites
A context-menu system. This plugin ships none and depends on none; it gives you the hook that lets every item instance carry menu behavior.
1. Choose the item instance class
Every item instance the plugin creates is of the class in Project Settings -> Crimson Inventory -> Items -> Item Instance Class (UCrimsonInventorySettings::ItemInstanceClass; UCrimsonInventoryItemInstance::GetInstanceClass() reads it). Subclass UCrimsonInventoryItemInstance, implement your menu system's provider interface on it, and set the setting to your class. CanPlayerAccess(Player, Pawn) is the ownership check your provider should run on the server before executing anything.
Create a Blueprint child of Crimson Inventory Item Instance, add your menu interface in Class Settings -> Interfaces, and set Item Instance Class to it in Project Settings.
Verify
Items created after the change are of your class (the Inventory Dev Tools Items tab shows the instance class).
(CrimsonCore - requires all Crimson plugins)
CrimsonCore ships the whole feature on CrimsonUI's context-menu framework: set
ItemInstanceClass=/Script/CrimsonCore.CrimsonCoreInventoryItemInstance, and author item-type action sets (UCrimsonInventoryItemTypeActionSet, project default in [/Script/CrimsonCore.CrimsonInventoryContextActionSettings] DefaultContextActionTypeSet) with the actions UCrimsonInventoryContextAction_Use, _Drop, _Equip, _Unequip, _Buy. CrimsonUI's wiki page How-To: Add Context Actions for Inventory Items walks the self-built version.See also
- How-To: Make an Item Usable
- API Reference