Example: Interaction + Inventory Loop (Blueprint) โ
This runnable example stitches together Interaction (trace + interface) and Inventory (DataAssets + replication) into a minimal, network-ready flow.
Goal
- Look at an item, press Use to pick it up, it goes to inventory, UI updates, save/load works, and it replicates correctly.
What you build
- Player Controller: Enhanced Input mapping for Use (IE_Triggered from an Action "IA_Use").
- Character: Line Trace for Objects + Interface call
IInteractable.Interact(Instigator)on focus actor. - Item Actor: Implements
IInteractable; has aPrimaryDataAssetreference defining ItemID, StackSize, Tags. - Inventory Component: ActorComponent with
ReplicatedUsingarray of FItemStacks; RPCsServer_AddItem,Server_RemoveItem. - UI: MVVM ViewModel observes Inventory; Widget binds to VM; shows item list.
- SaveGame: Struct snapshot of Inventory; Save/Load Service calls
UGameplayStaticssave functions.
Blueprint steps (high level)
- Create GameplayTags: Item.Consumable, Item.Weapon, Item.Currency.
- Create PDA
DA_Item_<Name>with fields:FName ItemID,FGameplayTagContainer Tags,int32 MaxStack. - Interface
BPI_Interactable:Interact(Actor Instigator). - Actor
BP_Pickup_<Name>: StaticMesh, PDA ref; Implements BPI_Interactable โ On Interact:GetOwnerInventory(Instigator) โ Server_AddItem(PDA, Count=1) โ DestroyActor. - Character
BP_Character: Camera; Tick or timer โLineTraceSingleByChannel(Visibility), if Hit ActorImplementsInterface, setFocusedActor; On Use Input:Execute_Interact(FocusedActor, self). - Component
BP_InventoryComponent:Replicatestrue; ArrayItemsofFItemStack { PDA, Count }withReplicatedUsing OnRep_Items. RPCs:Server_AddItem(PDA, Count); validate and merge stacks;OnRep_Itemsโ BroadcastOnInventoryChanged. - ViewModel
BP_InventoryVM: ExposeItemsas Array ofFItemView { Name, Icon, Count }; Bind to Inventory component viaOnInventoryChanged. - Widget
WBP_Inventory: ListView bound to VMItems. - Save/Load:
USaveGame_BP_InventorywithTArray<FItemSave { ItemID, Count }>; Service saves/loads and reconstructs using AssetManagerGetPrimaryAssetIdList. - Networking: Ensure Use input runs on owning client; Interact triggers Server RPC to mutate inventory; pickups are
bReplicateswithbNetLoadOnClientfalse.
Testing
- Singleplayer: pick up/destroy, UI updates, save then reload map, inventory restored.
- Multiplayer PIE 2 clients: authority-only mutations; late joiner sees current inventory via replication and OnRep.
Suggested prompts
- Add/extend prompts from the Interaction and Inventory pages to generate specific Blueprints and validation tests.
Prompts for this example
- "Generate the Blueprint steps to add
BP_InventoryComponentwithServer_AddItemRPC andOnRep_Itemshook; include variables and replication settings." - "Generate the Interactable interface (
BPI_Interactable) and implement it inBP_Pickup_Appleto add one item to the instigator's inventory on interact, then destroy self." - "Generate the MVVM ViewModel
BP_InventoryVMthat maps inventory items into aTArrayview for a ListView; detail bindings on theWBP_Inventorywidget." - "Write a Save/Load service Blueprint that snapshots and restores the inventory using
USaveGame; include a quick test sequence to verify."