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

How to request variables from the server

Discussion in 'Multiplayer' started by Lexeon, May 28, 2016.

  1. Lexeon

    Lexeon

    Joined:
    Apr 22, 2016
    Posts:
    23
    Yep, another noob networking question.

    My clients pass data to the server via the command attribute, and is stored on a gameobject that is only on the server. What I want to do is have the server return a variable, such as a Color, transform, string, GameObject, etc, down to the client (just one client, not all of them) whenever the client requests it. I have tried clientRPC, however, as far as I know, clientRPC methods cannot return variables. I have looked into server messages, but that looks a bit messy to be the only way to do this.

    For example, I store the positions and teams of the player on the server gameobject. When a client joins, it sends a request to the server to add it to a team, and the server adds it to a team in a playerlist gameobject. Now, I want to be able to have the client auto aim towards the closest player that is not on their team. So, the client needs to request information (the transform of a random player on another team) from the server gameobject. Please note that I will not need to request the information every update, so there won't be too many server calls.
     
  2. Lexeon

    Lexeon

    Joined:
    Apr 22, 2016
    Posts:
    23
    Bump. I got no further.
     
  3. _FLX

    _FLX

    Joined:
    Nov 10, 2015
    Posts:
    85
    http://docs.unity3d.com/Manual/UNetActions.html

    ClientRPC is not for returning variable, but you can give it a parameter for your client object.

    With NetworkMessage you can pass anykind of data in it
    (RPC & commands are restricted to simple types like float/int/string. With messages you can send advanced structs/classes).
    It's not that messy (i guess).
    Or syncvar.

    But since you're asking this kind of questions, is you game type fast ? Is your server authoritative ? How will you handle lag, and security ? You need to ask yourself these questions before because your game architecture depends of this.