I'm implementing an inventory system with items in 1x1 slots in a open-world multiplayer game. But I can't decide how I want to synchronize the item management with the server. I see two options here.

  1. Server and client are fully synced after every move. Synchronize every action the player takes in their inventory, even the action of "lifting" items.

  2. Server only syncs "when neccessary" An unordered list on the server keeeping track of WHAT items the player has and not WHERE (in what slot) they are. Then every time the player drops/uses/acquires or stacks/unstacks an item the client syncs their inventory including slot positions with the server.

Is there perhaps another option that's even better?


It really depends on your game, but three considerations you need to keep in mind are:

  1. Does the positioning in the inventory have any game-mechanical effect? When it does, you need to handle the inventory positions server-sided.
  2. When the player organizes their inventory how they see fit, logs out and back in again, their inventory will be a mess again. You could prevent this by storing the order on the client. But what if the player regularly accesses their account from different machines?
  3. Is there a limitation of inventory slots? When there is, item stack splitting and merging becomes a game mechanic, so you won't get around handling it server-sided.

However, when the player does a drag&drop, I would not recommend you to remove the item when they start dragging and put it back when they stop. There is a high risk that when a bug occurs while the user is dragging that the dragged item could get lost. There are also mechanical problems which might get hard to solve. What would happen, for example, when the player starts dragging an item, receives a new item while dragging which occupies the slot the item came from and then drops the first item at an invalid location? You can't revert it, because that would overwrite the new item.

Instead, wait for the player to drop the item, check where they dropped it, check if it's valid and then perform the swap-operation. While the user is dragging, the item still occupies the same place.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.