Hi everyone,
I am currently working on a multiplayer project using mirror that involves individual players having their own inventories as well as various storage inventories being present in the game world. These inventories are custom classes made up of custom slot classes that ultimately culminate into various integers and integer arrays. I have elected to store individual inventories on clients as I do not see a need to display my players inventories to one another, but I cannot seem to get my Command and ClientRpc methods to work when it comes to updating storage objects.
Currently my method has been to detect when the player interacts with a storage object on their own client which then utilizes the attached StorageObject component on the object which contains a regular method to update the inventory as well as calling a Command DataDeconstructor method which breaks the inventory down into its slots and their associated integers and arrays. This then proceeds to call a ClientRpc DataReconstructor method which passes the data making up each individual inventory slot and updates it.
This is the code called when the client closes the storage inventory
public void UpdateStorage()
{
storageObject.GetComponent<StorageObject>().UpdateStorage(playerStorageInventory);
storageOpen = false;
storageObject = null;
}
This is the code on the storage object and the method called by the player - Updates each slot on the inventory attached to the storage object and calls the DataDeconstructor
public void UpdateStorage(InventoryObject _updatedInventory)
{
Debug.Log("called UpdateStorage");
for (int i = 0; i < storageInventory.GetSlots.Length; i++)
{
storageInventory.GetSlots[i].UpdateSlot(_updatedInventory.GetSlots[i].item, _updatedInventory.GetSlots[i].amount, _updatedInventory.GetSlots[i].durability, _updatedInventory.GetSlots[i].storedItems, _updatedInventory.GetSlots[i].storedAmounts, _updatedInventory.GetSlots[i].storedDurabilities, _updatedInventory.GetSlots[i].storedItemsSlotID, _updatedInventory.GetSlots[i].storedItemsSlotAmount);
}
DataDeconstructor();
inUse = false;
}
This is the DataDeconstructor, is supposed to store the integers/arrays from each slot and pass them to the DataReconstructor
[Command]
public void DataDeconstructor()
{
Debug.Log("called dataDeconstructor");
for (int i = 0; i < storageInventory.GetSlots.Length; i++)
{
int itemIdstorageInventory = storageInventory.GetSlots[i].item.Id;
int itemAmount = storageInventory.GetSlots[i].amount;
int itemDurability = storageInventory.GetSlots[i].durability;
int[] itemStoredItems = storageInventory.GetSlots[i].storedItems;
int[] itemStoredAmounts = storageInventory.GetSlots[i].storedAmounts;
int[] itemStoredDurabilities = storageInventory.GetSlots[i].storedDurabilities;
int[] itemStoredItemsSlotId = storageInventory.GetSlots[i].storedItemsSlotID;
int[] itemStoredItemsSlotAmount = storageInventory.GetSlots[i].storedItemsSlotAmount;
DataReconstructor(i, itemIdstorageInventory, itemAmount, itemDurability, itemStoredItems, itemStoredAmounts, itemStoredDurabilities, itemStoredItemsSlotId, itemStoredItemsSlotAmount);
}
}
This is the DataReconstructor, is supposed to update each slot on the storage inventory for each client
[ClientRpc]
public void DataReconstructor(int _slotID, int _Id, int _amount, int _durability, int[] _storedItems, int[] _storedAmounts, int[] _storedDurabilities, int[] _storedItemsSlotID, int[] _storedItemsSlotAmount)
{
Debug.Log("called clientRpc");
for (int i = 0; i < storageInventory.GetSlots.Length; i++)
{
storageInventory.GetSlots[_slotID].UpdateSlot(storageInventory.GetSlots[_slotID].item, _amount, _durability, _storedItems, _storedAmounts, _storedDurabilities, _storedItemsSlotID, _storedItemsSlotAmount);
}
}
My issue is that even though I am not receiving any errors, my inventories will not update across clients and I cannot seem to figure out where I am going wrong. Does anyone have any advice? I may very well be using the Command and ClientRpc calls incorrectly. Any help is appreciated