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
  4. Dismiss Notice

Third Party RPC's don't work (PUN2)

Discussion in 'Multiplayer' started by Matexa, Aug 15, 2020.

  1. Matexa

    Matexa

    Joined:
    Oct 26, 2018
    Posts:
    2
    Hello, I just made a simple script that registers when everyone has chosen their team and then make the master client to send another RPC that will start the countdown. The problem is that playersReady is always 1 because it only runs the RPC locally.
    Code (CSharp):
    1. using Photon.Pun;
    2. using UnityEngine;
    3.  
    4. public class NetworkAvatar : MonoBehaviourPun
    5. {
    6.     public static NetworkAvatar localInstance;
    7.     public int playersInRoom, playersReady;
    8.  
    9.     private void Awake()
    10.     {
    11.         playersInRoom = PhotonNetwork.CurrentRoom.PlayerCount;
    12.         if (photonView.IsMine)
    13.             localInstance = this;
    14.     }
    15.  
    16.     public void TeamChosen()
    17.     {
    18.         photonView.RPC("RPC_TeamChosen", RpcTarget.MasterClient);
    19.         print("team chosen locally");
    20.     }
    21.  
    22.     [PunRPC]
    23.     private void RPC_TeamChosen()
    24.     {
    25.         print("RPC Called");
    26.         playersReady++;
    27.         if(playersReady == playersInRoom)
    28.         {
    29.             print("everyone's ready");
    30.             photonView.RPC("RPC_StartCounter", RpcTarget.All);
    31.         }
    32.     }
    33.     [PunRPC]
    34.     private void RPC_StartCounter() => RoomManager.Instance.StartCountdown();
    35. }
     
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
  3. Matexa

    Matexa

    Joined:
    Oct 26, 2018
    Posts:
    2
    Thanks! I was actually searching for a PUN server but every server invitation I found has expired :/
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    yeah it's easy to forget that tiny little foldout option that changes the invite duration.. discord ui
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    The RPC call is odd. It targets only one player:
    Code (CSharp):
    1. photonView.RPC("RPC_TeamChosen", RpcTarget.MasterClient);
    Send it to All.

    The Asteroids Demo from the PUN 2 package has a screen where players signal "ready" or not.
    There is also a Teams extension to PUN 2 in the UtilityScripts, which might be useful.
     
    Last edited: Aug 17, 2020