Photon RPC Functions Not Responding As Expected

Options
Hi, I'm having an issue that's I have been unable to solve over maybe 10 days of work.

I'm using Photon for Unity and I'm trying to implement a 'ready' system. Here is the code for how I'm trying to work it:
//On a non-networked GameObject
public void onUIClick()
    {
       //me is the player's GameObject
        me.GetComponent<PhotonView>().RPC("readyUp", PhotonTargets.AllBuffered);
    }
 
//On the networked player GameObject
[RPC]
    public void readyUp()
    {
        readyNumber += 1;
        Debug.Log(readyNumber);
        if (readyNumber == PhotonNetwork.playerList.Length)
        {
//going begins the game
            going();
        }
    }

What I feel should be happening is that when a player clicks the button, all players increment their 'readyNumber' integer. However what is actually happening is that only the client who clicked 'ready' increments to integer.

Could anyone share some advice on this matter?

Comments

  • Nonlin
    Options
    So from what I understand your issue is that the count isn't reflecting the actual amount of people ready?

    What I think it might be is that you are calling the RPC photonView of just "me" ?

    me.GetComponent<PhotonView>().RPC("readyUp", PhotonTargets.AllBuffered);

    Would call only yourself I think. If you had a global game object that managed the player counts with a photonView so that you could instead call something like

    photonView.RPC("readyUp", PhotonTargets.AllBuffered);

    Then all the players would receive it.

    At least that is what I think. I'm still pretty new to Photon.
  • Thanks for the response.

    But as far as the documentation states, specifying photonTargets.all should send the rpc to every client.

    However I think the idea of having a global synced object might be a good workaround. I'll give that a shot, thanks!
  • vadim
    Options
    More precise, calling RPC wih PhotonTargets.All on object instance will trigger RPC method on all instances of this object over network. So if you do not have such instance on some client, nothing will be called there.
  • Oooooooooh. Big ooooh. Okay, that might explain a few things.

    I'm still not entirely sure why debugging was showing me actions when I called the RPC from another object but that may well explain the shortcomings in my current workings.

    I've also discovered room custom properties so I'm going to experiment with that, but between custom properties and ensuring I call the RPC on an object that is synced across the network I'm feeling confident I can get somewhere.