How client can send data(int) to another client ???

Options
I make simple project. With 1 param "int test", when Client press button -> test+=5; And changed data send to clients.
Bit it works just when MasterClient (host) changing param... when client changing param it's don't work. I use interface "IPunObservable" and script Photon View. I add video to this discussion, can u help me how client can send changed data to another client ?

video with problem: https://youtu.be/u65q_MHdrjI
project link: https://github.com/iceprinc/PhotonNetwork-TEST

code:
using System.Collections;
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
using System;

public class PhotonController : MonoBehaviourPunCallbacks, IPunObservable
{
    public Text testText;
    private bool connected = false;
    private int test = 0;
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(test);
        }
        if (stream.IsReading)
        {
            test = (int)stream.ReceiveNext();
        }

    }
    private void Start()
    {
        PhotonNetwork.NickName = $"Player {UnityEngine.Random.Range(1000, 9999)}";
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.GameVersion = "1";
        PhotonNetwork.ConnectUsingSettings();
        Log("Connecting");
    }
    private void Update()
    {
        if (connected == true)
        {
            Log(Convert.ToString(test));
        }
    }
    public void ClickTestButton()
    {
        test += 5;
        Debug.Log($"Local test = {test}");
    }
    public void ClickCreateRoom()
    {
        Log("Create room");
        PhotonNetwork.CreateRoom(null, new Photon.Realtime.RoomOptions { MaxPlayers = 4 });
    }
    public void ClickJoinRoom()
    {
        Log("Joinning room");
        PhotonNetwork.JoinRandomRoom();
    }
    public override void OnConnectedToMaster()
    {
        Log("ConnectedToMaster");
    }
    public override void OnJoinedRoom()
    {
        Log("Connected");
        connected = true;
    }
    private void Log(string message)
    {
        Debug.Log(message);
        testText.text = message;
    }

}

Comments

  • Some one help
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @IcePrince,

    Thank you for choosing Photon!

    This is by design, scene networked objects are controlled by Master Client only.
    Read more here.
    And stream.IsWriting is true only if photonView.IsMine is true.

    So I suggest that you use an RPC with target MasterClient or PhotonView owner to request value change:
    public void ClickTestButton()
        {
            if (photonView.IsMine)
            {
                AddFive();
            }
            else
            {
                photonView.RPC("AddFive", RpcTarget.MasterClient);
                //photonView.RPC("AddFive", photonView.Controller);
            }
            Debug.Log($"Local test = {test}");
        }
    
        [PunRPC]
        private void AddFive()
        {
           test += 5;
        }