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

UNet Multiplayer Help - Calling Functions with Commands not Working

Discussion in 'Editor & General Support' started by Mattrhorn, Oct 23, 2018.

  1. Mattrhorn

    Mattrhorn

    Joined:
    Jun 22, 2018
    Posts:
    1
    Hey, Im pretty new to Unity (and this is my first post here) but after searching everyone on the internet for a solution I have come up with nothing. (Apologies if this is in the wrong forum section)

    Little Background Information: I am trying to develop a Multiplayer Board Game (turn based) that is managed through multiple path objects. The Path Objects are predefined in the game hierarchy and when a player loads, the player object has a script attached which gets the Path Component from each of those Path Game Objects. The Path objects are successful at grabbing them (I check to see whether they return null or not) But when I change a value on that path from a Client, a get a return error (See Figure 1 below)

    upload_2018-10-22_22-26-18.png
    (Figure 1)

    From what Ive read on the Internet, when a Client Calls a Cmd Function it is ran as if it was done by the server. I have placed the code below for reference. The Code Below occurs when a button is pressed, which calls the "CallRPCFunction" (I know its not actually calling an RPC Function it was just a previous name when it was that I didnt change)

    Code (CSharp):
    1. [Command] public void CmdTestFunction(int i, int j, bool n){
    2.         Debug.Log("SetGenerator Called");
    3.         paths[i,j].hasGen = n;
    4.     }
    5.    
    6.  
    7.     public void CallRPCFunction(){
    8.         CmdTestFunction(1,1,false);
    9.     }
    When the Player joins the server in the first place, he creates an Array of Paths (paths[,]) which is populated with the Finding of each path. What appears to happen above is it is trying to change the value of the path of the Client from the server and thats where it is failing. NOTE: The Path Objects are not spawned, they are in the game (See image below)

    upload_2018-10-22_22-34-38.png

    Im not sure if maybe I simply have the wrong concept of how this is supposed to work, but I am just trying to find a way to keep the paths[,] synced up between the players, and nothing I seem to do or research works. Any help/assistance getting through this would be very much appreciated.

    Thanks.