Photon 2 InvalidCastException: Specified cast is not valid. RigidBodyView

Options
Wherever i try to get in the scene with the client appears this error:
InvalidCastException: Specified cast is not valid.
Photon.Pun.PhotonRigidbodyView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonRigidbodyView.cs:76)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:638)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:628)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1819)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2190)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3142)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:659)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:575)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1829)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)

And this is the code that doesn't works:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) 
    { 
         if (stream.IsWriting) 
         { 
             stream.SendNext(this.m_Body.position); 
             stream.SendNext(this.m_Body.rotation);

             if (this.m_SynchronizeVelocity)
             {
                 stream.SendNext(this.m_Body.velocity);
             }
             if (this.m_SynchronizeAngularVelocity)
             {
                 stream.SendNext(this.m_Body.angularVelocity);
             }
         }
         else if (stream.IsReading)
         {
             this.m_NetworkRotation = (Quaternion)stream.ReceiveNext();
             this.m_NetworkPosition = (Vector3)stream.ReceiveNext();
             if (this.m_TeleportEnabled)
             {
                 if (Vector3.Distance(this.m_Body.position, this.m_NetworkPosition) > this.m_TeleportIfDistanceGreaterThan)
                 {
                     this.m_Body.position = this.m_NetworkPosition;
                 }
             }
             
             if (this.m_SynchronizeVelocity || this.m_SynchronizeAngularVelocity)
             {
                 float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime));
                 if (this.m_SynchronizeVelocity)
                 {
                     this.m_Body.velocity = (Vector3)stream.ReceiveNext();
                     this.m_NetworkPosition += this.m_Body.velocity * lag;
                     this.m_Distance = Vector3.Distance(this.m_Body.position, this.m_NetworkPosition);
                 }
                 if (this.m_SynchronizeAngularVelocity)
                 {
                     this.m_Body.angularVelocity = (Vector3)stream.ReceiveNext();
                     this.m_NetworkRotation = Quaternion.Euler(this.m_Body.angularVelocity * lag) * this.m_NetworkRotation;
                     this.m_Angle = Quaternion.Angle(this.m_Body.rotation, this.m_NetworkRotation);
                 }
             }
         }
     }

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @agustin9594,

    Thank you for choosing Photon and sorry for the delay!

    What PUN 2 version is this?
    When you try the Asteroids demo scene provided in the package, can you reproduce?
    Did you modify PhotonRigidbodyView or any other PUN 2 code?