SyncList Callback only called when changed, but not when first transferred to the client

I have a SyncListStruct for which I have a callback, which I declare on OnStartClient.

Everything works fine and it’s syncing - but the callback is called only with the first change of the list*(and following changes).* When the client first receives the info, the callback is not called. Is there a way to have it called also when the client receives the list the first time?

Thanks.

Yep, the docs state the callback is only done for incremental updates. The function “OnStartClient” is called the first time the variable is setup though.

Your SyncVars are guaranteed to be “up to date” before OnStartClient is called so you can do your modifications then. eg:

   [SyncVar(hook="OnSync")]
   var myBool = false;

    public override void OnStartClient() {
        // Called when spawned remotely by server.
        Init();
    }

   void OnSync(bool newVal) {
      myBool = newVal;
      Init();
   }

   void Init() {
      if (myBool) { ... }
   }

Ah thanks very much, good to know that it will for sure be up to date then. Question, where do you see that guarantee in the docs? I believe I saw some connection flow somewhere in the docs, but can’t seem to find it right now :slight_smile:

Nevermind, found it here:
http://docs.unity3d.com/Manual/UNetSpawning.html
:slight_smile: