[SyncVar] Some glitches or something else

Hi there. I’ve got strange logic with sync vars.
I try to explain. I’ve got 2 sync vars.
int speed = 15;
int health = 100;

On server it’s always good. It’s math correct and etc.
But when connected new client - he got strange values of that vars, like
int speed = 187;
int health = 220;

All commands and rpc’s and all math logic work good at all clients and server. There only a glitch with correct sync values at startup.

Intresting that only client can’t get right sync values. Maybe someone knows whats wrong with conncection or something?

You would have to post the code to take a look

public class Charecter : NetworkBehaviour {

    [SyncVar(hook = "OnSyncSpeedUpdate")]
    public int syncRunSpeed = 15;

    [SyncVar(hook = "OnSyncHealthUpdate")]
    public int syncHealth = 100;

    [SyncVar(hook = "OnSyncCriticalDamageUpdate")]
    private bool syncCriticalDamage = false;

    public int maxHealth = 100;

    public GameObject defaultWeapon = null;

    private Animator animator = null;
    private UIMessages messages = null;

   
    public void OnSyncSpeedUpdate(int runSpeed) {
        LG.log("SYNC OnSyncSpeedUpdate :: " + runSpeed);
        syncRunSpeed = runSpeed;
    }
    public void OnSyncHealthUpdate(int health) {
        LG.log("SYNC OnSyncHealthUpdate :: " + health);
        syncHealth = health;
    }
    public void OnSyncCriticalDamageUpdate(bool criticalDamage) {
        LG.log("SYNC OnSyncCriticalDamageUpdate :: " + criticalDamage);
        syncCriticalDamage = criticalDamage;
    }
}

At client connect there no hooks and all “players” have wrong sync values at the client.
At server

Custom Logs:

At client

Custom Logs:

I can’t see anything wrong in your code. Perhaps try without the hooks and see if that works.

This is “magic”, because i add hooks to log values to handle it and to see whats wrong. At the end i fix it.
Some way my Charecter class was to big for syncronizing - there is transforms, animations, triggers, e.t.c. and that stats like speed, health. I create new network class for player prefab that contains only sync vars and it’s math\changing logics and it start to work good. I think there was some conflict in sync vars with animations(it’s bones based and there many vars on it)

By default UNET can handle 32 syncvars/lists per NetworkBehaviour. But you should receive errors if you have too many.