Synchronizing animations over Unet

Good day,
I have some special case here. Im trying to make a school project, which is using Unet. I synced players positions etc. just fine, so it’s working. But I want to sync their variables, to know what should they do on the other side. So, my idea for synchronizing animations sounds like this: I have a script on each player, which is deleted, if its not local player. I will also make animating script, with functions like void GetAnimId(int id), which I will call as localplayer, and sending ID to it (like 1 should mean idle, 2 should mean walking, 3 jump etc.), and the animations will be processed locally on each client like this. But here come’s the problem, how to synchronize it from local player’s script (of the animation one) to other animation scripts? I only need to send the INT variable on each tick. I tried using [Syncvar (hook = “OnChangeAnim”] but it doesnt work as I want, the function can ONLY be called from server. I want it to be called from local player to others. Thanks for any of your ideas.

Regards,
Peter.

SyncVars can only be sent from Server → Client, never from Client → Server

There are 2 ways using UNET to send information from Client → Server
1: [Command]
2: MessageBase

What I do to sync data from a client to everybody is use Message Base. I sent a message from Client → Server and then the server reads the message and repeats it to all other clients (excluding the original client sender and the server’s client). It ends up being pretty complicated to sync something as simple as an integer.

Alternatively you can use [Command] to send a message to the server containing integer info. Then the server sets an integer [SyncVar] to all clients. But this has it’s own issues as well (there are SyncVar bugs and also the owner either has a latency delay or has to have special code to ignore the syncVar hook).

1 Like

Thanks very much! Could you please give me some example code, which will do stuff automatically? As input, there should be void SetInt (int a) and then it should be processed. I’ve seen those things like Command and Syncvar before, but still can’t imagine, how to combine them in this scenario.

  • Thanks for help very much, somehow I finally did it by some video :slight_smile: