Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party [Photon]The observed monobehaviour (XXX) of this PhotonView does not implement OnPhotonSer

Discussion in 'Multiplayer' started by Wtyson, Dec 18, 2015.

  1. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    57
    so no idea why im getting this error
    sorry for the bold just trying to split code and reg typing
    Code (CSharp):
    1. The observed monobehaviour (FredPS(Clone)) of this PhotonView does not implement OnPhotonSerializeView()!
    2. UnityEngine.Debug:LogError(Object)
    3. PhotonView:ExecuteComponentOnSerialize(Component, PhotonStream, PhotonMessageInfo) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:515)
    4. PhotonView:SerializeComponent(Component, PhotonStream, PhotonMessageInfo) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:434)
    5. PhotonView:SerializeView(PhotonStream, PhotonMessageInfo) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:327)
    6. NetworkingPeer:OnSerializeWrite(PhotonView) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3493)
    7. NetworkingPeer:RunViewUpdate() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3414)
    8. PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:132)

    its not even calling a script. just the base game object
    so im quite confused

    i use the following
    Code (CSharp):
    1. void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    2. {
    3. if (stream.isWriting)
    4. {
    5.  
    6. stream.SendNext(health);
    7. }
    8. else
    9. {
    10.  
    11. health = (float)stream.ReceiveNext();
    12. }
    13. }
    is all im sending at the moment

    but yet i still get this error i fires this error 3 times and because of this i cant seem to update my health values



    i use
    Code (CSharp):
    1.   [PunRPC]
    2.     public void GetShot(float damage)
    3.     {
    4.         health -= damage;
    5.         if (health <= 0 && photonView.isMine)
    6.         {
    7.             if (RespawnPlayer != null)
    8.                 RespawnPlayer(3f);
    9.  
    10.             PhotonNetwork.Destroy(gameObject);
    11.         }
    12.     }
    and i call the punrpc within this

    Code (CSharp):
    1. void TempShooting()
    2. {
    3.  
    4.  
    5.  
    6. RaycastHit hit;
    7.  
    8. if (Physics.Raycast(firePos.transform.position, firePos.transform.forward, out hit, Mathf.Infinity))
    9. {
    10.  
    11. Debug.DrawRay(firePos.transform.position, firePos.transform.forward, Color.red);
    12. if (hit.transform.tag == "Player")
    13. {
    14. hit.transform.GetComponent().RPC("GetShot", PhotonTargets.All, GunDamage);
    15. }
    16.  
    17.  
    18.  
    19.  
    20. }
    21. }

    and on update i have my input for firing ...

    Code (CSharp):
    1. if (photonView.isMine)
    2. {
    3.  
    4. if (Input.GetKeyDown(fire))
    5. {
    6. TempShooting();
    7. }
    8.  
    9.  
    10. }

    Any Help on this would be great thanks !
     
  2. MidgardDev

    MidgardDev

    Joined:
    Dec 11, 2012
    Posts:
    47
    Hi, does that script inherit from PhotonBehaviour or Monobehaviour? If it does inherit from Monobehaviour, try to instead inherit from PhotonBehaviour, it might do the trick.
     
  3. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    57
    yeah it inherits from photon.monobehavior other wise i cant use photonView
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Wtyson: Maybe it's a config issue. In the prefab's PhotonView, remove the currently observed scripts from the list and drag&drop the script into the observed fiel again (make sure it's the one script with OnPhotonSerializeView() in it).

    From that error, it's not entirely clear, if the observed script is actually of the correct type you expect.
     
  5. BadSeedProductions

    BadSeedProductions

    Joined:
    Dec 26, 2014
    Posts:
    144
  6. profesar

    profesar

    Joined:
    Sep 29, 2016
    Posts:
    2
    Same issue
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @BadSeedProductions, @profesar: Which version of PUN and Unity are we talking about?

    In best case, your component implements IPunObservable.
    PUN won't use an inherited OnPhotonSerializeView method on components.
     
  8. Blinkq

    Blinkq

    Joined:
    Apr 19, 2015
    Posts:
    21
    Hey guys.
    You should inherite
    IPunObservable
    and Implement func like thiis :)
    void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){ ... }
     
  9. vselockov

    vselockov

    Joined:
    May 10, 2018
    Posts:
    10
    Hey, blinkq that give error `photonConnect.IPunObservable.OnPhotonSerializeView(PhotonStream, PhotonMessageInfo)': containing type does not implement interface `IPunObservable'
     
  10. CrosshairGames

    CrosshairGames

    Joined:
    Aug 10, 2020
    Posts:
    1
    can someone simplify in dumby terms how to fix this
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    PhotonViews can "observe" scripts. The idea is that those scripts write the content for regular updates about this object. The controlling player for a PhotonView writes those, others read.
    Any script that is in the "Observed" list of a PhotonView has to implement the interface IPunObservable.
    In your case, some script is in said list but does not implement the interface.
     
  12. JavierOlvera

    JavierOlvera

    Joined:
    Sep 10, 2019
    Posts:
    11
    You just have to add an OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){ ... } (it can be empty if you want, you just need the function) into the script that the object in the error message has. It does not make sense to me but works fine, good luck to everyone!
     
  13. Taobao

    Taobao

    Joined:
    Oct 25, 2015
    Posts:
    9
    Using
    public void OnPhotonSerializeView
    instead of simple
    void OnPhotonSerializeView
    silved this issue for me. I was using inherited classes.
     
    tobiass likes this.
  14. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Glad you found it and thanks for sharing the fix!
     
  15. innocentmax6367

    innocentmax6367

    Joined:
    Dec 27, 2020
    Posts:
    2
    was into same issue , All i had to do was making a script that implements

    Code (CSharp):
    1. [RequireComponent(typeof(PhotonView))]
    2.  
    3. public class character_script : Photon.MonoBehaviour, IPunObservable
    4. {
    5.  
    6.  
    7. // then the function
    8. public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    9.     {
    10.         if (stream.isWriting)
    11.         {
    12.             //We own this player: send the others our data
    13.             stream.SendNext(transform.position);
    14.             stream.SendNext(transform.rotation);
    15.         }
    16.         else
    17.         {
    18.             //Network player, receive data
    19.          Vector3   correctPlayerPos = (Vector3)stream.ReceiveNext();
    20.           Vector3  correctPlayerRot = (Quaternion)stream.ReceiveNext();
    21.         }
    22.     }
    23. }
    Then in Component PhotonView ,Observed Components slot i draged and droped the script