Unet : SyncVar Not Syncing! Tried everything

I have tried everything I could and wasted a lot of time on this very worthless topic but I still dont get why this doesnt work… The client updates the value and it does not sync to the editor (who is hosting) where the value is still the default one (-1).

[SyncVar]
    public int survivorID = -1; //Starts from 1...

public override void OnStartLocalPlayer()
    {
        if (!isLocalPlayer)
        {
            return;
        }
         killer = FindObjectOfType<Killer>();
        StartCoroutine(SettingSurvIDs());
    }

IEnumerator SettingSurvIDs()
    {
        yield return new WaitForSeconds(0.3f);
        CmdSetSurvivorID();
    }

    [Command]
    void CmdSetSurvivorID()
    {
        survivorID = int.Parse(netId.ToString()) - (int.Parse(killer.numberOfSurvivors.ToString())+2);
    }

EDIT : I am well aware that I don’t need to add the islocalplayer check there but as I said I’m trying everything that I can

Syncvars only sync from server → client, client → server will not work.

Read the documentation carfully next time.

He called a Command so it’s fine.

I guess the reason is OnStartLocalPlayer() try to change it to Start() but check for if(isLocalPlayer);

@TheWesselGames I don’t mean to be rude but please at least read the code when I’m saying I have tried everything before commenting that.

1 Like

Unfortunately that doesnt work :(. I even tried putting it in update but still doesnt work.

Fixed it! The problem was not with the SyncVar itself. It was with the killer object not being assigned on the server properly. It wasn’t even throwing any errors until I decided to debug the thing i was setting the survivorID to… It works fine now! Thanks for your time.

1 Like