Search Unity

Question Syncing Ghost data to single client

Discussion in 'Entity Component System' started by Weschk, Sep 28, 2020.

  1. Weschk

    Weschk

    Joined:
    Sep 2, 2020
    Posts:
    1
    Hello!

    I'm trying to make a server authoritative game with 2-8 players, each player have some data that should be synced to all other clients but some data that should remain a secret for all but your own client and the server.
    Something like this:
    Code (CSharp):
    1.  public struct ItemData: IComponentData
    2.     {
    3.        //shared to all
    4.         [GhostDefaultField]
    5.         public int playerId;
    6.         [GhostDefaultField]
    7.         public int type;
    8.         [GhostDefaultField]
    9.         public int numberOfItems;
    10.      
    11.         //Should only be visible to the owning client
    12.         [GhostDefaultField]
    13.         public int itemIdentifier;
    14.      
    15. }
    I was looking trough the code of the DOTSSample project and found the Player.State struct contained a section with a comment saying "These are only sync'hed to owning client" but I am having a really hard time figuring out what makes these "owner only" and where the logic for only passing these items to the owning client happens, looking a the serializer it looks like all fields are always serialized.

    I know I could send the information from the server to the client via RPC but feels like a more sound approach just to have to manage the game state on the server letting the clients send their RPCs to the server and get the whole state back via ghosts.

    Anyone have any suggestion or pointers on how to do this or is it not possible?

    Thanks for the help!