Search Unity

How to assign reference to a variable on clients

Discussion in 'Multiplayer' started by hakankaraduman, Oct 8, 2017.

  1. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    My game is played with maximum 4 players. Each can instantiate(spawn) object with authority. They do it through a Command invoke.

    So I call Command, and on the server the object is instantiated and spawned with authority.
    After that step, I want to have reference to that instantiated object on the GamePlayer object with a new script. I can set it now but only with a ClientRPC call and there must be at least two GameObject parameters.
    One is the GamePlayer object that I want to access to it's script and set this script's variable, the other parameter is the GameObject reference of newly instantiated/spawned object.

    Is there an easier way to do it?
    Does it cost too much to send GameObject references with Command and ClientRPC calls. Also

    I realized I can't put Custom C# class parameters in those command and clientrpc functions, and also can't make those custom monobehaviour variables as SyncVar.

    Is what I do bad for optimization? Should I proceed with this method of implementation.
     
    Last edited: Oct 11, 2017
  2. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    Second question;

    I need to get MatchInfoSnapshot instance of newly created match. I can get it when joining as a client but docs are not saying how to get it after creating the match.

    I need this because I want to set a seed integer from the match name string for all players, to create a procedural terrain same for all players.

    ---

    I'll workaround it with this way if anyone needs something like this, inside OnMatchCreate callback, I listed all matches again with the created match's name as a filter. And then in a foreach loop, I checked if the created game's network id and the snapshots network id is the same or not, if it's the same, I use that snapshot.
     
    Last edited: Oct 11, 2017