I have been following this tutorial on how to create an inventory system.
I’ve gotten to the point I want to store items in a separate actor (video #13). I’m trying to figure out how to modify his process so it replicates.
Currently I run transferring items on a server RPC. That works and the host is able to deposit and retrieve items. The host is also able to retrieve items a client deposits, but I am having a really hard time getting the client to be able to see/retrieve items. I would think that after the the items are added to the other actor on the server I should have a rep notify, but I can’t figure out where/which variable to put it on.
Make sure both the client and the server have the corresponding inventory objects or components.
When you add an item to the inventory make sure an RPC is called and the exact same item is added in the corresponding server inventory too. This will handle your client->server communication.
Make sure the inventory object component is marked as replicated and all values that you’ll use are also replicated. This will handle your server->all clients communications.
Now you should be able to see your inventory on all clients.
P.S. I’m sorry but I don’t have the time to watch through the videos so I’m not really sure what your setup is.
Agreed, which is what I did to get the inventory transferred to the storage actor. But now when I go to retrieve items from the storage nothing happens for the client (works great for the host). My print string on the host shows that the storage actor has a populated inventory and the client shows an empty inventory. So when the client attempts to retrieve the items it says there’s nothing there to retrieve. I’ll add screenshots tonight. It seems like an ownership issue, or like I have a variable/component that should be set to replicate that isn’t.
Within the blueprint component the selected amount of items are removed from the player’s inventory, a “pickup pack” actor is spawned (if not already), and the same quantity of items that were removed from the player’s inventory are added to the pickup pack by the server.
On Clicked (B_DropQuantity) needs to call an event on the SERVER. So RPC (Item name, Amount, unique id)
Server executes the Drop item by amount.
Server also has to be the proxy that spawns the pickup pack.
Pickup Pack actor needs to be set to Replicate.
Server then Adds items to the pack.
BPC Inventory needs to set to Replicates.
I think I’ve done that now. However, the client still isn’t retrieving any resources from the pack. I had thought I needed to make sure that the resources existed in the pack for the client but maybe they don’t, and perhaps it should all be run on the server’s version of the pack anyways. So I changed my code for the pickup to try and get the server to add the items to the client’s inventory, but that didn’t work either.
I’ve got it now! I had to set the overlapping controller to be the owner, then switch has authority. It still wasn’t adding it to the client’s inventory though so I added the run on client RPC back in and it works!