Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Server auth. state sync. framework with client side prediction and server reconciliation

Discussion in 'General Discussion' started by Roni92pl, Aug 10, 2020.

  1. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396


    Hello I managed to create general purpose server authoritative state synchronization(sass) with client side prediction(csp) and server reconciliation(sr) framework. The most obvious use case being server authoritative fps movement with csp and sr - but of course since it's framework you can use it to sync any data you want, even single float.
    It is effect of many refactors and tests to be as flexible as possible and automate as much as possible writing sass with csp and sr.
    The most important point of this framework is to 'automatically' handle and isolate csp and sr code(but no magic!), while user provides only actual game logic code.
    It is basically one abstract class that you derive from that handle and hide from you all ugly csp and sr logic,
    so you don't have to worry about it - you just provide inputs and object states - more on that later.

    The basic setup of framework consist of 3 main elements:
    AuthoritativeStateHandler - main, abstract class, handles csp and sr internally, have reference to two other elements
    INetworkObject - networked object reference, necessary to determine if it's client, server and network time
    IAuthoritativeDataTransport - class responsible for actual data communication, implementation of this will depend on your network solution

    Framework is built on a few assumptions:
    • Minimal amount of code is necessary (basically just input processing and setting state are necessary) and also so there is no need for developer to understand (rather complex) or even see mechanics of client side prediction etc - all this logic is already in abstract AuthoritativeStateHandler class
    • One, same class for client and server
    • All logic is decoupled from network transport
    • Will work with host architecture 'by default' - no explicit treatment of host should be needed
    • If all abstract methods are implemented correctly, and input processing is deterministic this framework should guarantee proper state synchronization with client side prediction and server reconciliation, where data(state) is always server-authoritative
    • It can be used to synchronize any data/state as long as input processing is deterministic

    This is how minimal implementation looks like, you have to provide only 4 simple, isolated methods - input processing and getting/setting object state:


    IAuthoritativeDataTransport:

    This is interface you need to implement that will handle network transport part.
     
    Last edited: Aug 10, 2020
    TwoTen and LinuXY like this.
  2. mike1997

    mike1997

    Joined:
    Jul 1, 2016
    Posts:
    25
    looks very interesting especially after watching overwatch tech video, do you plan to have network framework specific implementation, if so which project (forge, mlapi, mirror?)

    I found this thread through forge discord channel, anything with forge planned?
     
  3. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396
    Thanks, my current implementation is with MLAPI, though I'd like to try it with Mirror too.
    Current implementation is modified fps controller from standard assets wtih synced looking around with mouse, moving, crouching, and running.

    If I make product out of this, MLAPI and Mirror are two implementations that I would want to provide, can't tell much about Forge, as afaik it's not very actively developed project anymore.

    I could also provide pure framework itself without any implementation, but I don't know if there would be demand for it.
     
  4. GerardSimpson

    GerardSimpson

    Joined:
    Jun 6, 2017
    Posts:
    7