[ServerRpc]
public void TearClothServerRpc(NetworkObjectReference itemReference)
{
if (!IsHost && !IsServer) return;
if (itemReference.TryGet(out var itemObject))
{
ItemManager itemManager = ManagerObject.Instance.GetManager(ManagerType.ItemManager) as ItemManager;
Item cloth = itemObject.GetComponent<Item>();
Item item = itemManager.SpawnItem(itemManager.FindItemByName("Other Item"), _playerInventory.transform.position);
// item.gameObject.SetActive(false)
item.isPickedUp = _playerInventory.CanStoreItem(item);
// item.gameObject.SetActive(!item.isPickedUp);
print(item.isPickedUp);
if (!item.isPickedUp)
{
HandleDrop(item, _playerInventory.transform.position + Vector3.up);
}
TearClothClientRpc(itemReference, item.NetworkObject, item.isPickedUp);
// cloth.NetworkObject.Despawn(false);
}
}
[ClientRpc]
public void TearClothClientRpc(NetworkObjectReference itemReference,
NetworkObjectReference newItemReference, bool canPickup)
{
if (itemReference.TryGet(out var itemObject) && newItemReference.TryGet(out var newItemObject))
{
Item cloth = itemObject.GetComponent<Item>();
Item newItem = newItemObject.GetComponent<Item>();
cloth.ParentContainer.Remove(cloth);
// Destroy(cloth.gameObject);
newItem.gameObject.SetActive(!canPickup);
if (canPickup)
{
_playerInventory.Pickup(newItem);
}
}
}
When Despawn is done on ServerRpc to use and remove the item, ClientRpc cannot access the item’s data.
I don’t think it’s a good way to use Invoke or Coroutine. Is there a good way?