I am currently working on a multiplayer inventory system and have ran into some issues when it comes to replication.
My setup so far is that the Inventory is an Actor Component that is set to replicate using the SetIsReplicated() function. Inside this component there is an array of items also set to replicate. I have the override for the function GetLifetimeReplicatedProps() as well.
The issue I am having is that the Players are using their UI (which isn’t replicated) to modify the Inventory by dragging and dropping items around. The one thing I did manage to get working is to make the main function which decides what changes to perform and executes them, a Server RPC. From the inventory slot class I call this by checking the authority of the owner of the inventory component in question.
Now this does update everything on the server and it is showing correct values, however nothing gets replicated down to the client and the UI shows wrong information. I have tried setting Always Relevant on the actors using this component and setting them to replicate as well but to no avail. I am using multicast delegates to signal the UI that it needs to refresh its shown information whenever anything changes in the inventory array.
Does anyone have a clue on what I am missing here exactly?
Hard to say without knowing how the inventory works, but by dragging and dropping around do you mean just visually? Is that important to the server? You also shouldn’t need a multicast to update the UI that is only relevant for one person. It would help to share how you have it structured
And that is it. Debugging this shows that the server has the correct value after the user changes something but the client doesn’t. This is the item array I was referring to, it is using a custom struct I made (don’t know if that could be a problem):
Okay I have managed to find a solution to this. Basically in order to get this working, I used a Server RPC to modify the items array and I used the ‘ReplicatedUsing’ property on the items array itself.
The delegates that update the UI are in this OnRep method and this way it all works like a charm. The very important thing to note here is that the Server RPC has to be called from the actor component that is attached to a Player controlled actor, trying to call it from other components will not trigger the method at all and you will get undefined behavior.