Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity Networking RPC not working except on the user that sent it. C#

Discussion in 'Multiplayer' started by wolfpack4417, Jun 3, 2015.

  1. wolfpack4417

    wolfpack4417

    Joined:
    Jul 5, 2014
    Posts:
    8
    Hey guys,

    I've started to make a multiplayer game and the first thing I am working on is the lobby. This is an RPC function I wrote and it is being called on every machine but not working.

    The purpose of the function is to update the image next to my player's name with the class icon of the character class that the player chose. The RPC is going through to every machine, because I can see the Debug.Log printed on server and client, but the image only updates on the machine that actually called the RPC function.

    Here is the code:

    Code (CSharp):
    1. [RPC]
    2.     void UpdatePlayerImages()
    3.     {
    4.         Debug.Log ("updated information for player at position " + playerPosition);
    5.         playerImageSpots[playerPosition].GetComponent<Image>().sprite = iconImages[(int)characterClass];
    6.     }

    and this is how I call it:

    Code (CSharp):
    1. public void OnSkillScreenReadyButtonClick()
    2.     {
    3.         ShowPlayerPanel();
    4.         nView.RPC("UpdatePlayerImages", RPCMode.AllBuffered);
    5.     }
    and this is where I set nView

    Code (CSharp):
    1. void Start ()
    2.     {
    3.         nView = GetComponent<NetworkView>();
    4.     }
    5.  
    Can anyone help me with this. I think I'm just not understanding something. I've read through most of the API and the Unity Networking Guides, but it's hard to wrap my head around all of it.

    Thanks,
    Tucker
     
  2. wolfpack4417

    wolfpack4417

    Joined:
    Jul 5, 2014
    Posts:
    8
    I figured it out. Mods you can delete this. I wasn't sending the player position and characterClass as parameters so it was using the local variables instead.