Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

Discussion in 'Connected Games' started by Wtyson, Dec 18, 2015.

  1. Wtyson

    Wtyson

    Joined:
    Aug 15, 2014
    Posts:
    53
    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:
    53
    yeah it inherits from photon.monobehavior other wise i cant use photonView
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,415
    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:
    138
  6. profesar

    profesar

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

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,415
    @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:
    20
    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:
    7
    Hey, blinkq that give error `photonConnect.IPunObservable.OnPhotonSerializeView(PhotonStream, PhotonMessageInfo)': containing type does not implement interface `IPunObservable'
     
unityunity