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

New Users - Help Understand RPCs

Discussion in 'Multiplayer' started by HarrisC, Apr 9, 2014.

  1. HarrisC

    HarrisC

    Joined:
    Mar 26, 2014
    Posts:
    1
    Hi all,

    So I just started with Unity last week and am trying to figure out how exactly RPC's can be used.

    I would like to have a server which is just a standalone application that creates a server
    Code (csharp):
    1. Network.InitializeServer(maxNumPlayers, serverPort, false);
    and stays open.

    However, I seem to be struggling with doing this and using RPC's. For example I have a chat system that consists of a game object in all clients, with an attached script that uses rpc's. I call the RPC using
    Code (csharp):
    1. networkView.RPC ("SendChatMsg", RPCMode.All, msgToSend);
    and the RPC is defined lower in the code as
    Code (csharp):
    1. [RPC]
    2.     void SendChatMsg(string msg) {
    3.         chatLog = chatLog + "Message: " + msg + "\n";
    4.     }
    My problem is that when I make the networkView.RPC call, it seems to call the function on the same client, but does not call it on any other networked clients.

    What am I missing here? Does the RPC need to exist on the server as well with a game object and everything?

    Thank you for your help!
     
    Last edited: Apr 9, 2014
  2. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    168
    When you call a RPC, you call it from the local player (your pc,as client) to the player that is located on the server, the player that is supposed to be you.
    So, when you call networkview.RPC , you are calling your player that lives on the server side,you are not calling the other players.
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I am not too sure if maybe all your clients just create a server? First step would be to make sure the clients you expect on one server are actually there.
    Aside from that, the RPC just calls a method on the networked GameObject on all active clients in the same game.