Hello, while working on my game’s inventory system I noticed that when players connect after the host grabs an object, it will still appear there which isn’t the only problem, I’ll explain what’s going on. You can see it here ([webbuild](http:// http://snsservers.com/rpg/unity-gameproject-build.html), Q to open inventory, E to grab items) if you open two tabs.
Basically each player class has its own inventory List which stores GameObjects and is updated to everyone whenever the player grabs or uses an item (e.g. I grab a sword, I equip it → other player runs the same methods as the main player’s which uses its own inventory, so keeping it updated is important). Although when a player joins after the host modified his inventory, it doesn’t sync. Here’s what I thought:
Should I send each player’s inventory(list) on player join?
But how would that sync grabbed items created after the host grabbed in-scene created objects?
If I had to remake all the inventory/items system for something more efficient I’d gladly do it so please, suggest anything. This is my first time trying to make a game in Unity and asking something here by the way.
If you need scripts let me know and I’ll edit the post, thanks for reading.
Forgive me for not answering the question directly, but why do you want to sync the inventory? Btw - you can’t send gameobjects over the network. You’ll need to identify them with a string or integer.
I’ve done some stuff so far and managed to make inventory work without having to sync nor using gameobject (I’m using prefabs in resources now).
Although I’m still having problems in syncing the scene, that’s what it all is about really. If I grab an item and make it disappear, Network.Destroy gives problems and Destroying on everyone’s view will not destroy it in new players’ view.
Another thing is instatiating objects, same problems as for destroy. Lastly are components, how do I update all clients that components are removed/added? Do I have to do that everytime?
Underneath everything is sending and receiving data. Send data in the right way, and interpret them on the reception. You can do this with RPCs for example. Send a buffered RPC that tells everyone what item is there.
I’m still curious why you would want to sync an inventory though. Most games only need players to see their own inventories. When someone needs to trade, that’s when you sync with the specific person.
That’s what I’m trying to do but I’m trying to find a solution which doesn’t require me to check for each component an item has and confront it with its default and THEN add what’s missing/remove what’s more. It sounds pretty uneffective.
No, no, I don’t need that anymore. As I said I managed to avoid needing that.