Saving inventory in multiplayer not working

So… basically i’ve got an inventory saving system for multiplayer:

Saving and Loading Functions (Blueprint Function Library)


Inventory / Item Array Transfer Events (Player Character)

Items Array To Inventory in Event BeginPlay (Player Character)

Inventory To Items Array (Inventory Widget)

Saving Before Traveling (Travel Box Actor)

Loading and Saving Again After Traveling (Player Controller BeginPlay)

And this is what happens in-game:



As you see, the client’s items, for some reason, gets the server’s items.

Anyone knows how to solve this?

Thanks in advance! :slight_smile:

so it works on server but not on client?

what are all those random delay nodes?

i dont think you need the multiplayer bool because if its singleplayer it will have server authority.

The server is the one who saves and loads

When u enter the level a loading screen appears, 1 second is delayed just to make sure every player is in, if player is server then it will load and with a delay of 0,2 seconds to make sure its loaded, it will save again. then the last 0,3 seconds are just for aesthetics.

Ik, just added it to make it easier to “access” but it does the same as the ue5 default booleans

those delays don’t ensure anything, a player could load, or not and you have no way of knowing.

your multiplayer bool isnt replicated so clients could go the false path and load their own game, but as i said i see no reason for this bool, only the server should load

the multiplayer bool is from the game instance, so it doesnt need to be replicated.

equally the things you mentioned are not part of the problem as they were tested using prints and i can confirm that players load correctly before executing the save and load functions.

also testing a little bit more i can confirm that the clients’ items doesnt get saved.

the delays might work in editor but likely not in a packaged game, just trying to save you some future pain.

so based off what you said if the client isnt saving but is loading the servers inventory check if your controller ref is correct

the client isnt saving or loading either, is the server who has the savegame. Also what i need to ref is the player character not the controller, which i tried to do using “Get Owning Player Pawn” (5th image)

what im saying is a. make sure theyre valid and b. make sure they are the ref your expecting.

in your final pic you said the client is getting the server items so it is loading it just has the wrong ref from somewhere

yea youre right
Captura de pantalla 2024-03-03 101657
Both numbers of items should be 3 but for some reason the client doesnt save their items.

Still seeing the problem in-game i dont know where the problem is in-code (i think its getting the player pawn in widget) but still could you indicate me what to do? thx in advance!

so your items array is null on client?

looking at that your using a widget but widgets only exists on clients. my guess is when you setitems your clearing the array the client returns null and doesnt repopulate it.

Well, still i dont have any other component where i can call the set items array event as its supposed to get called when an item is added or dropped. So what can I do?

where is your item array right now?

adding and removing all needs to be server side. you replicate the array to the clients and the clients can have widgets display the data but not alter it

Item array is in the player character. This should work like this: when the client drops or picks an item an event is called. This event clears the array, gets all items and adds them to the array. Then the server when saving event is called gets the array from the client and adds it to another array in the SaveGame.

why clear it at all? why not just add/remove the item?

either way it has to be done server side.

currently if you clear it server side the widgets will fail (or be a server copy) and if you do it client side the widgets may work but the items will be overwritten by server since it has authority and its replicated

I clear it bc if i dont do it then the current items will stack on the previous items

also cant figure out how to do it as server side as items are stored in the widget.

so yea idk what to do basically

i think you’ll have to redesign unfortunately, although it shouldnt be too bad. you’ve already got the items array.

make it repnotify, when you add/remove do a server call and on repnotify event update your client widgets. widgets should only be for display

hey! srry for answering late, i was full of exams.

anyway. I followed your steps and remade the item adding and removing system.

so what happens now is that when i pick up an item, it adds to the items array but it doesnt display on the widget (image below to prove its in the array)

Captura de pantalla 2024-03-16 154711

Here’s the code (All inside Player Character)

ty in advance!

where are you telling the widget to update? you’re setting the item but you’ll need a function to update the icon etc

also OnRep isnt always called on server so what id do is make a function UpdateInventory and call it when the server changes and in the OnRep for clients

Making the UpdateInventory function works the item display issue. Now the issue is that when the items are saved happens something… weird
(The first player had 2 items and the second 3)
Captura de pantalla 2024-03-17 161007

likely one of your Refs is wrong, you know the deal, whack a print string on everything and see where you dont get the desired result