PhotonView Detected you dropped a Component missing IPunObservable Interface error

So im making a flood escape game and i wanted to see how many people escaped. So i made a script to see how many people steped on the block and escaped. But when i tried to put the script in the photon view it said this error “PhotonView Detected you dropped a Component missing IPunObservable Interface”. I have no idea how to fix it here is the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class bob : MonoBehaviour {
    public int players;
    public Text text;
   public PhotonView photonview;
	// Use this for initialization
	void Start () {
        text.text = "you and " + players + "survived";
        photonview = GetComponent<PhotonView>();
	}
   
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(players);
        }
        else
            players = (int)stream.ReceiveNext();
    }
    
    // Update is called once per frame
    void Update () {

        text.text = ""+players;
		if (Input.GetKey(KeyCode.B))
        {
            players++;
        }
	}
}

,So im working on a flood escape game and I want to say how many people are alive. I made a script to see how many people steped on a block and escaped. But when I tried to put the script in the Photon view componet, it said this error “PhotonView Detected you dropped a Component missing IPunObservable Interface,”. Here is the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class bob : MonoBehaviour {
    public int players;
    public Text text;
   public PhotonView photonview;
	// Use this for initialization
	void Start () {
        text.text = "you and " + players + "survived";
        photonview = GetComponent<PhotonView>();
	}
   
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(players);
        }
        else
            players = (int)stream.ReceiveNext();
    }
    
    // Update is called once per frame
    void Update () {

        text.text = ""+players;
		if (Input.GetKey(KeyCode.B))
        {
            players++;
        }
	}
}
1 Like

Hey there,

seems you are using photon2. When you used photon2 and want to implement a stream you need to let your script inherit from the interface class Photon.Pun.IPunObservable.

So change your class implementation to the line

public class bob : MonoBehaviour, Photon.Pun.IPunObservable {

With that your error will be gone. Note though that it will probably ask you to implement some functions that are given by the interface class itself. Just add them as empty functions to your script.
You can look up the interfaces HERE

Let me know if anything was unclear or if there are any further questions.

thank you so much. it said reward user so i did. i have no idea what it does it just said 1 point left so i gave you all of my points. again, thank you so much.