SyncVar strange behaviour on LocalPlayerAuthority object

I have a NetworkBehaviour script which contains a SyncVar int. If I check LocalPlayerAuthority on the GameObject, the SyncVar int’s value become “out of control” on the local player.

By “out of control”, this is what I observed in the debug log:
-int is initialized and sync-ed correctly,;
-an instant later hook function gets called on client for about 40 times attempting to change the value to 66, 63 and 65 in a random manner
-sometimes the int is hooked to set consecutively for the same value like 65 for 5 times in a row.
-after a while hook function gets called to set to a larger variety of numbers
-few seconds later since above, hook function stops getting called and the int stopped at the value 179

The only place where I touch this int is OnStartServer() where I set it to 100, and the hook function setting the int to the argument of the hook.

Is this a bug? but looks pretty crazy to be a bug and from what I read about how SyncVar work this seem too strange also no one else seem to be having problem with SyncVar so I’m not sure if I have totally misunderstood something. Any insight is appreciated, thank you.

I use [SyncVar] with floats on LocalPlayerAuthority objects and not experiencing this. Do you have some kind of feedback loop somewhere?

Just attached another test script to the LocalPlayerAuthority object:

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class test : NetworkBehaviour {

  [SyncVar(hook="OnUpdate")]
  public int TestValue;

   public override void OnStartServer () {
  base.OnStartServer();
  TestValue = 2;
   }

  public override void OnStartLocalPlayer()
  {
  base.OnStartLocalPlayer();
  TestValue = 3;
  }

   void OnUpdate (int newValue) {
  Debug.Log("Oldvalue: " + TestValue);
  TestValue = newValue;
  Debug.Log("Newvalue: " + newValue);
   }
}

Nowhere else touches TestValue, in the log I get:
Oldvalue: 3
Newvalue: 2
Oldvalue: 2
Newvalue: 1777
Oldvalue: 1777
Newvalue: 185
Oldvalue: 185
Newvalue: 230
Oldvalue: 230
Newvalue: -734295235
Oldvalue: -734295235
Newvalue: 235
Oldvalue: 235
Newvalue: 36
Oldvalue: 36
Newvalue: 902839807

no more logs afterwards

Do SyncVar work when the GameObject has multiple NetworkBehaviour components attached ( though I don’t recall reading anywhere mentioning it)?

Basically I have 3 scripts on my object which I separate the GameObject’s function into. I have one script which poll player input, one script which give instruction based on the input result and one script (where all SyncVar are supposed to live in) which store game data like current score for the player. I suspect the system do not like my setup…

Those value changes seem pretty weird and random.
Mine do have multiple NetworkBehaviours, but I’m not using the default callbacks. I have one that does basic logic, one that handles controlling and one that changes appearance properties.
I use the Client Message Handlers and RPCs/Commands.

Thanks so multiple NetworkBehaviours do work.

Well in the original script I referred to on topic I only used Start() and regardless the weird behaviour still happened so I don’t think the problem is due to these callbacks. I guess I will file in a bug with a clean project…

Have you tried the patch at https://unity3d.com/unity/qa/patch-releases? There are some UNet syncing fixes in there.

Didn’t know such thing exists lol, thanks man I will give it a try!

Edit: Yes the patched version solved the problem concerned.