Modular UI Integration
Building inventory widgets
The MP_Inventory frontend is entirely decoupled from the backend logic. The plugin does not force a specific UI implementation. Developers can use standard Unreal Motion Graphics (UMG) components to build their interfaces.
Data Objects for UI Lists
To integrate with UMG UListView or UTileView, the plugin utilizes a Data Object pattern.
- UMP_InventoryUIItem: A
UObjectwrapper that stores a copy of theFMP_InventoryItemstruct. - When the inventory updates, the UI generates or updates
UMP_InventoryUIItemobjects and passes them to the list view. - The UI widgets implement the
IUserObjectListEntryinterface to receive theUMP_InventoryUIItemdata and update their visual state (e.g., icons, quantities).
Subscribing to Delegates
The UI reacts to server-authoritative changes by binding to delegates on the UMP_InventoryComponent and UMP_InventoryManager.
Component Delegates
Bind to these delegates on the UMP_InventoryComponent to monitor the main inventory state:
OnInventoryUpdated(FName InventoryID, EInventoryDelta Delta, int32 SlotIndex): Triggered for any mutation (Add, Remove, Update) within the physical array for UI.
Manager Delegates
Bind to these delegates on the UMP_InventoryManager to monitor overall state and nearby items:
OnInventoryActionNotify(FName Reason): Triggered for operations failures/successes.OnInventoryAccessUpdate(FName InventoryID, bool bHasAccess): Triggered when security authorization is granted or revoked.OnInventorySync(bool bSave, FName InventoryID): Triggered after data serialization completes.OnNearbyLootChanged(EInventoryDelta Delta, int32 SlotIndex): Triggered when a ground item registers or unregisters from the local tracking array.- Object References: The
UMP_InventoryUIItemused for proximity loot holds a directAActor* GroundActorpointer. This provides O(1) direct reference to the physical actor in the world.
Building the Interface
- Initialize: On UI construction, obtain a reference to the local Player Controller's
UMP_InventoryManager. - Bind: Bind custom events to the required delegates.
- Populate: Read the current state of the
FMP_InventoryFastArrayand instantiateUMP_InventoryUIItemobjects for existing items. - Execute: Route player inputs (clicks, drags) to the
UMP_InventoryManagerRPCs (e.g.,SwapItemsBetweenInventories).