Issue with Inventory Component Replication in Multiplayer (Client-Side)

Hi all,

I’m having trouble with my inventory system in a multiplayer project in Unreal Engine. The server is accurately tracking the inventory, but the client HUD is not reflecting the changes correctly. Here’s a summary of my setup and what I’ve already tried:

Setup:

  • Inventory Component: Attached to the player’s pawn (BP_Player_Character). It tracks an Items array that is set to RepNotify.
  • HUD: Displays the player’s inventory, which references the pawn to access it’s Inventory Component to update the UI.
  • Replication:
    • Items array is marked as RepNotify.
    • Inventory Component is set to replicate (both in class defaults and on the component itself).
    • The pawn is correctly replicated and controlled on the client.

What’s Working:

  • Inventory system and HUD is working as intended for the Server pawn.
  • The OnRep_Items function fires on the client when the server modifies the inventory. I confirmed this with print statements.
  • PlayerController references a pawn on the client (BP_Player_Character_C_2), this pawn is valid and all other functionality is working as expected (movement, interactions, attacks).
  • The server correctly tracks the inventory for the client’s pawn. It is able to add new items and detect when the inventory is full.

The Problem:

  • Despite OnRep_Items firing and replication seemingly working, the inventory HUD does not update on the client side.
  • Changes to the Items array on the Inventory Component aren’t being reflected in the HUD.

What I’ve Tried:

  1. Double-checked replication settings: Both the Inventory Component and Items array are set to replicate.
  2. Reassigning the array after modification to ensure OnRep_Items triggers.
  3. Fetching the Inventory Component from the client’s pawn in OnRep_Items to update the HUD.
  4. **Creating a custom event that runs on owning client to force update of HUD.

What could be causing the inventory changes to replicate but not properly reflect on the client HUD? Based on my testing it seems like the issue is either the replication of the inventory component on the remote pawn, OR the Pawn reference is somehow invalid on the HUD.

Any help would be appreciated!

Does OnRep_Items call an event or function to update the Hud… loop through inventory etc?

Yep that’s correct. The OnRep_Items function calls an Event Dispatcher which is listened to by the HUD. When that event is called the HUD then updates its display to show the items in the array.

The solution that I ended up using was to have the client perform the logic of the inventory. Before I was doing all inventory logic on the server and replicating it down to the owning client.

For anyone that runs into a similar issue my old logic was:
Client calls interact → Server gets closest item → Server adds that item to the inventory → Server destroys the Item actor → Server replicates the Inventory to the owning client → Owning client updates it’s HUD

The new logic looks like this:
Client calls interact → Server gets closest item → Server calls Multicast for owning client to add item to its inventory → Server destroys the Item actor → Owning client updates it’s HUD

I’ll need to do more reading but I think this approach might be exploitable for players who want to cheat by injecting items into their inventory. But this is a non-competitive coop multiplayer game so its not a concern for me.

First approach was the correct one.

I store inventory in the player state as a replicated actor component and each struct, actor obj is replicated. The inventory structs etc are repnotify (reliable). All my UI is handled by the controller.

Client calls interact → Server gets closest item → Server adds that item to the inventory → Server destroys the Item actor.

The Onrep function uses control logic is autonomous proxy to fire off a call to the controller to update the UI.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.