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

Third Party PUN Weird behaviour PunRPC

Discussion in 'Multiplayer' started by jomsa, Oct 29, 2016.

  1. jomsa

    jomsa

    Joined:
    Nov 10, 2013
    Posts:
    23
    Okay so i have this

    Code (CSharp):
    1.  
    2. public static int stuff = 0;
    3.  
    4. [PunRPC]
    5. void addStuff() {
    6. Debug.Log("called");
    7. stuff++;
    8. }
    And i call it by
    Code (CSharp):
    1. PhotonView.Get(this).RPC("addStuff",PhotonTargets.MasterClient);

    Then when i start the application everything seems Ok.

    But when client connects, the "stuff" variable is set to 3 yet log shows that addStuff was called only twice.

    The heck is happening here? I am totally confused.

    Quick answers much appreciated.
    thanks
     
  2. jomsa

    jomsa

    Joined:
    Nov 10, 2013
    Posts:
    23
    Also if third player connects, the stuff value gets to 8 allready.. Somesort of multiplying is happening here, but i dont get it.. why and how???

    Also the host's log does not even log the third call...
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    I guess you are calling addStuff when someone joins? Everyone seems to call it whenever anyone joins.
    There are separate callbacks for "when someone joined" and "when this client got into a room". See PunBehaviour docs.
     
  4. jomsa

    jomsa

    Joined:
    Nov 10, 2013
    Posts:
    23
    Thanks i'll look into that.

    I call it on player spawn.. but then i realized that maybe i am going all the wrong way with this. Might need to call it, as you said on more.. specific time and .. on more authorative basis sort of.. hard to explain.