How-To: Add Context Actions for Inventory Items

Goal: right-click an item in your inventory UI and get Use, Drop or Equip entries that run on the server. CrimsonUI ships the context-menu framework; the actions for your item type are yours to write, because this plugin knows nothing about any inventory.

Prerequisites
A context menu already opens (How-To: Show a Context Menu), and the owning player controller has a UCrimsonContextActionPlayerComponent. Your item is a UObject (an item instance, a data object) that the server can find again from the request.

1. Write an action

An action is a UCrimsonContextAction subclass. Set its DisplayName, ActionTag, ExecutionPolicy (Server for anything that changes gameplay state) and optional ConfirmationMode. Override ShouldShow / CanExecute to hide or gray it out, and ExecuteAction to do the work - on the server, against Context.Target.

Create a Blueprint Class with parent Crimson Context Action, name it CA_UseItem. Override Should Show (return true when Context -> Target is your item class), Can Execute (fill Out Reason when blocked) and Execute Action: Context -> Target -> Cast To <your item> -> <your use function>. Set Execution Policy = Server in Class Defaults.

Verify
The class appears in class pickers under Crimson Context Action.

2. Offer the actions from the item

The gatherer asks the target for its actions. Either implement ICrimsonContextActionProvider on the item class (GatherContextActions, plus DescribeContext to add situation tags such as "in my bag" or "equipped" that actions gate on with ShowWhen / HideWhen), or keep the item untouched and register a world-level ICrimsonContextActionContributor with UCrimsonContextActionContributorRegistry::RegisterContributor, which appends actions for any target it recognizes. A UCrimsonContextActionSet data asset is a convenient way to author the action list once and share it.

On your item Blueprint: Class Settings -> Interfaces -> Add -> Crimson Context Action Provider, then implement Gather Context Actions: for each action in your UCrimsonContextActionSet (or a hard-coded array), Add it to Out Actions.

Validate on the server
The server re-runs the same gather when a pick arrives and executes only an action it found itself. Keep ShouldShow / CanExecute deterministic on both sides, and put ownership checks in ValidateContextActionRequest (C++ only) so a client cannot act on another player's item.
Verify
Right-click the item: the entries appear. Pick one in Play As Client: the effect happens on the server and replicates back; picking on another player's item is rejected.
(CrimsonCore - requires all Crimson plugins)
CrimsonCore ships a complete reference for its inventory: the actions UCrimsonInventoryContextAction_Use, _Drop, _Equip, _Unequip, _Buy and UCrimsonInventoryQuantityContextAction, the item-type action set UCrimsonInventoryItemTypeActionSet, the item instance UCrimsonCoreInventoryItemInstance (implements the provider, describes the situation and validates ownership), and UCrimsonInventoryContextActionStatics::GetContextActionsForItem, all under CrimsonCore/Source/CrimsonCore/Public/Integration/Inventory/. Read them as a worked example of steps 1 and 2.

See also

  • How-To: Show a Context Menu
  • API Reference