Inventory: DataAssets + Replication (Blueprint)
What/Why: A minimal, replicated inventory that keeps logic in components and data in PDAs. Spawns visuals from soft references.
Prereqs
- Gameplay Tags plugin (for categorization and cooldowns)
DA_ItemDatafrom the Data Assets section
Steps
- Inventory Component
BP_InventoryComponent(replicated): Array ofFItemEntry { Id: Name, Count: int }- Events:
OnItemAdded(Id, Count),OnItemRemoved(Id, Count)(dispatchers) - Functions:
AddItem(Id, Delta)(Server): find or add entry; clamp non-negative; FireOnItemAddedRemoveItem(Id, Delta)(Server): reduce; remove when zero; FireOnItemRemovedHasItem(Id, Count) -> bool
- Replication: mark array Replicated; OnRep to update UI/ViewModels
- Equipping visuals
EquipItem(Id):- Resolve
DA_ItemDatavia Asset Manager - Async load Mesh/MI; set on a Mesh Component (or attach spawned Actor)
- Store current equipped Id for replication; OnRep apply visuals on clients
- Resolve
- UI bindings
- ViewModel
VM_Inventorywith a list of entries (Id, Count, DisplayName) - Listen to InventoryComponent dispatchers; update VM; bind to
WBP_Inventory
- Pickup and use
- Pickup Actor implements
BPI_Interactable.Interact→ callsServer AddItem(Id, Count)on the player’s InventoryComponent - Use action calls
Server RemoveItemand triggers gameplay effect/animation
Data
DA_ItemDataholds DisplayName, Soft Mesh/Icon, Weight, Tags (Item.Type., Rarity.)
Networking
- Only server mutates inventory; clients request via Server RPC
- Replicate inventory entries to owning client; keep visuals authoritative but synced
Performance
- Batch UI updates; debounce OnRep calls to avoid re-render storms
- Async load visuals once per equip; reuse instances
Testing
- Single and multiplayer test maps: pick up items, verify counts replicate
- Equip an item and confirm visuals appear on all clients
Suggested prompts
- “Blueprint-only. Create a replicated
BP_InventoryComponentwith add/remove, OnRep updates, and dispatchers for UI.” - “Show how to equip an item by resolving a
DA_ItemDataand async-loading its mesh, then replicating the equipped state.” - “Provide a pickup interactable that calls
Server AddItemon the player’s component.”
Prompts for this example
- “Write the OnRep logic to rebuild
VM_Inventoryfrom the replicated array and updateWBP_Inventory.” - “Show nodes to resolve an item Id to PDA via Asset Manager, then async-load and set the mesh on a component.”