Sending basic information across the network is failing? *SOLVED*

Hi, I'm trying to send some basic information about each individual player across the network.
For reference, I understand custom properties, but later on, this script will carry much more data with various variables that change frequently. Health,ping and other things.

I'm trying to send the data across the network using 'OnPhotonSerializeView'. So all players can see the information in the script.

The purpose of this script is that I can get access to each players information fairly easily by passing the viewID of the player and then using 'getcomponent<Player_Information>();'

The OnPhotonSerializeView doesn't seem to run until there are multiple players in the game. That makes sense and is fine.
But the errors I get are:
'Error: you cannot read this stream that you are writing!'
It also throws and null reference error on the: 'PlayerPing = (int)stream.ReceiveNext();' line.

What am I fundamentally doing wrong here?

The script is in the observable photonview. The script is also attached to the player. The photonview is on the same object as this script.

I even looked through the sample files, they all seem to do what I'm trying to achieve in the same way.

Am I missing something?Am I being a complete idiot?

I hope someone can explain and put me in right direction.

Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class Player_Information : MonoBehaviourPun, IPunObservable
{
    // Start is called before the first frame update
    [SerializeField]
    string PlayerName;
    [SerializeField]
    int PlayerPing;

    [SerializeField]
    string PlayerTeam;

    public Network_Character NC_Script;
    bool Update_Ping = true;

    bool Update_Info = true;


    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (PhotonNetwork.IsConnected && GetComponent<PhotonView>().IsMine == false)
        {

            return;
        }


        //empty name
        if (PlayerName.Length == 0)
        {
            Update_Name();
        }

        if (PlayerTeam.Length == 0)
        {
            Update_Team();
        }

        if (Update_Ping)
        {

            StartCoroutine(Update_Players_Ping());

        }




    }


    void Update_Team()
    {
        if (NC_Script.IsHuman)
        {
            PlayerTeam = "Team Blue";
        }
        else
        {
            PlayerTeam = "Team Red";
        }
    }

    void Update_Name()
    {
        PlayerName = PlayerPrefs.GetString("nickname");

    }


    IEnumerator Update_Players_Ping()
    {
        Update_Ping = false;
        //update ping every 3 seconds
        while (true)
        {
            PlayerPing = PhotonNetwork.GetPing();

            yield return new WaitForSecondsRealtime(3);

        }


    }


    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        { //This is if I am sending data to the server
            stream.SendNext(PlayerPing);
        }
        else
        { // if I am not sending data to the server then I must be receiving data
            PlayerPing = (int)stream.ReceiveNext();
        }
    }

}

Comments

  • *Solved*
    Emotitron helped me solve this. For some bizarre reason I had a bool called isWriting inside my photostream class. I have no idea how it got there.
    It should have been IsWriting instead of 'isWriting'