Just wondering, why would inventory items need to be synced to all other players?? If my local player has items in his inventory, the remote players don’t need to know that, only the server/host does, to check/allow items being used.
I can just use cmd and rpc to keep track of local player inventory - as in for server to auth pickups/usage and anti cheat?
Or am I misunderstanding SyncVars?
SyncVars take the Server value of the variable and force it upon the Clients.
If the server is authorative and you’re using a SyncVar for each item in the inventory you’re probably wasting a lot of bandwidth. A better way might be to have the Server give the client a base state of their inventory, then when the client does something that will change the inventory it goes through the server, the server approves/denies and sends the command to do it on the client.
// for this client
public virtual void DropItem()
{
CmdDropItem();
}
[Command] // for the server
public virtual void CmdDropItem()
{
if (!canDropItem) return;
RpcDropItem();
}
[ClientRpc] // for the other clients
public virtual void RpcDropItem()
{
StartCoroutine(ActuallyDropItem());
}
Something like that is what I mean. Its really vague, but I think you kinda get the idea.
Here’s some general notes I wrote down for myself.
// Notes:
// [Command] is for a CLIENT telling the SERVER to run this method.
// [ClientRpc] is for a SERVER telling ALL CLIENTS to run this method.
// [Server] means the code can only be run on the SERVER.
// [SyncVar] forces the SERVER value of the variable to ALL CLIENTS.
That’s fantastic, thankyou, and what I suspected. That makes perfect sense.
I’m coming over from photon pun to unet as I think I’ve wrapped my head around photon quite well but think that Unet will be the way for me going forward. This is going to be a pleasure I can see now ![]()