Clients Only Receive or Send

My client, which creates the room, can send currentLevel data to other clients and they receive it. But my other clients cannot send data or the room creator client cannot receive data I am not sure. I can successfully instantiate object, but when using stream I do not understand what I did wrong, it looks simple.
[code2=csharp]void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
Debug.Log("Send current level: " +currentLevel);
stream.SendNext(currentLevel);

}
else
{
// Network player, receive data
int getCurrentLevel = (int)stream.ReceiveNext();
Debug.Log("Received current level: " + getCurrentLevel);
this.currentLevel = getCurrentLevel;
}
}[/code2]

and the other necessary part:

[code2=csharp]void OnGUI () {
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
if (GUI.Button (new Rect(10,100,100,30),"Start Server"))
{
PhotonNetwork.ConnectUsingSettings("0.1");
Debug.Log("Connected");
}
}

// CALLBACKS
void OnJoinedLobby()
{
PhotonNetwork.JoinRandomRoom();
Debug.Log("Room joined");
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
Debug.Log("Room Created");
}[/code2]

Comments

  • Use rpc calls to update values from any client.
    OnPhotonSerializeView always reads values from script of owner (creator in your case) and writes them to others.
  • Thank you. When I also add this part it worked.
    [code2=csharp][RPC]
    public void sendLevel(int updateLevel)
    {
    currentLevel = updateLevel;
    }[/code2]

    But I have a question for understanding the issue better. Do we always have to remain this part:
    [code2=csharp]public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    // We own this player: send the others our data
    stream.SendNext(currentLevel);
    }
    else
    {
    // Network player, receive data
    this.currentLevel = (int)stream.ReceiveNext();
    }
    }[/code2]

    with the RPC function along with it? Sending both by RPC function and stream.SendNext(currentLevel), stream.ReceiveNext() at the same time looks strange to me.
  • You definitely do not need OnPhotonSerializeView. Rpc does all the work.
  • You can also use PhotonNetwork.LoadLevel after setting PhotonNetwork.automaticallySyncScene = true in your clients.
    It might do what you want.