After multiple methods and hours of programming to try to come up with a solution, I still cannot see a way of doing this. Let me explain what I am trying to do:
I have a server, which when started, will generate loads of GameObjects with a script (lootableScript.cs) attached. This script defines the GameObject to be ‘lootable’ and allows the player to bring up a loot menu and take objects etc. The script contains a List (lootTable) which can be transfered to the players inventory and at the same time, will remove it from the container - that all works on a single machine.
To ‘create’ the GameObjects, a script running on the server will spawn an amount of items using :
Network.Instantiate(objectToSpawn, position, rotation, 0);
The objectToSpawn is a prefab already loaded - they are all the same object. Each of these objects has a lootableScript with an identical lootTable - each contains the same two items in the List. If I remove an item from one of the objects by looting it, it will be removed in that instance of the game - but obviously not in the other connected players.
I have tried a few ways to sync these components, here are my issues:
- You cannot pass GameObjects or Components via an RPC - so I cannot simply send the state of each List
- networkView seems to be the same, you can use state sync to do this, however, only the owner can send, in this case, the server is the owner, therefore the server will not know when a player has taken something from a list.
TL;DR
I want to know what the best way of having the server ‘owning’ a group of GameObjects (as the server will be instantiating them) and a simple way to not only keep the existance, position and rotation of each one in sync across the network, but also to be able to keep a script WITHIN these GameObjects in sync - or more importantly, the List<Inv_InventoryItem> in sync across the network.
REALLY LAZY VERSION.
I take gun out of box, it disappears from box on all clients. That’s MY GUN.
Thanks guys in advanced, any help will be appreciated.