# How do I Sync data from client to server?

I'm trying to Sync data from the client to the server using the new Unity Networking, and I'm failing for some reason.

I've set up a prefab with a NetworkIdentity component with the attribute Local Player Authority set.

I (manually) spawn that on the server, and it is correctly propagated to the clients.

I have a couple of vars on this class, which the client sets and the server should read:

public class PlayerController : NetworkBehaviour
{
[SyncVar] public bool engineOn;
[SyncVar] public Quaternion lookAt;


The client correctly sets them, however the server never receives them, they always stay at the default value.

What might be happening?

• The alternative is using Command, but I would like to understand if I can get it to work using SyncVar. – o0'. Jun 15 '15 at 16:56

[SyncVar] only sends messages from the server to the client. You need [Command].

• You confirm this is also true even for objects with Local Player Authority? – o0'. Jul 8 '15 at 10:28
• PS: why the downvote? – o0'. Jul 8 '15 at 10:28
• Yes, I tested it on my cumputer and checked online document even if with Local Player Authority – Ricardo Jul 12 '15 at 17:18

Not sure if this has been figured out or but here goes. I dropped the [SyncVar] portion except for health and shields on players and used the following code to get by break lights to sync across network.

void LateUpdate () {

if (isLocalPlayer) {
if (Input.GetButton ("Fire1")) {
breakLightsOnOff = true;
} else {
breakLightsOnOff = false;
}
CmdBLC (breakLightsOnOff);
}
}

[Command]
void CmdBLC(bool OnOff) {
RpcBreakLightControl (OnOff);
}

[ClientRpc]
void RpcBreakLightControl(bool OnOff) {
breakLights.SetActive (OnOff);
}

• This was a huge help for me as I was using Command methods and SyncVars but hadn't used Rpc methods – SuckerForMayhem Mar 1 '17 at 3:48

The problem is that Server will never receive these updates unless there is a LocalClient on the machine running the server. Refer unity docs for the word Host i.e. Sever and a Client

• So, local authority has no effect on syncvars? That would be very counter-intuitive… – o0'. Jun 21 '15 at 8:16
• The intension was to be able to turn any Single Player Game to Multiplayer in a few hours. If there is a client on the Server as well, one does not have to write special code for remote client and local client. It may be Counter-Intuitive but it is Productive. This way games can have dedicated servers. – Sri Krishna Paritala Jun 21 '15 at 17:21