Search Unity

Callbacks for Network Sync?

Discussion in 'Multiplayer' started by emotitron, Dec 17, 2016.

  1. emotitron

    emotitron

    Joined:
    Oct 9, 2016
    Posts:
    41
    I am just digging into multiplayer and have gotten the basics working, but immediately I discovered the same shortcomings with interpolation as others and need to roll my own.

    So my question is - Is there some way to get a callback on synced vars and transforms rather than have to test for changes every update? In this case I need to be able to trigger code that calculates the implied vector velocity of enemy players based on the last two received transform syncs, which then can be used to extrapolate location while waiting for the next update.

    The documentation isn't the easiest to find answers on this, and none of the tutorials seem to dig deep enough to expose this kind of functionality.
     
  2. emotitron

    emotitron

    Joined:
    Oct 9, 2016
    Posts:
    41
  3. DWit

    DWit

    Joined:
    Dec 4, 2016
    Posts:
    25
    What you are looking is hook:
    Example:
    Code (csharp):
    1.  
    2. [SyncVar(hook="ValueSync")]
    3. int value = 0;
    4.  
    5. void ValueSync(int newValue) {
    6.    //it only fires when value is changed
    7.    //so client can change value which he received from server
    8.    value = newValue;
    9.    //add event after value change here
    10. }
    11.  
     
    Last edited: Dec 18, 2016
    MrLucid72 likes this.
  4. emotitron

    emotitron

    Joined:
    Oct 9, 2016
    Posts:
    41
    Thanks man, I've been slowly digging up those methods since my original post - but they aren't all in obvious places. Seems like the UNet stuff is pretty new and simple uncluttered snippets are still a bit hard to find without some digging.