"InvalidCastException: Specified cast is not valid." when using PhotonTransformView (Pun 2.7)

Hello,

I simply added a PhotonTransformView to a prefab that is instantiated with Photon and it causes the following error in Unity's Console (at runtime):

InvalidCastException: Specified cast is not valid.
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Tools/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2018)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Tools/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2579)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:633)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:545)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1473)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Tools/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:130)
And the instantiated objects aren't synchronised on both clients.

Maybe this is because the level prefix is sent as a byte, but read as a short?

PS: I also dragged and dropped the PhotonTransformView component to the list of observed components of the PhotonView.

Edit: If I avoid using SetLevelPrefix() then the error disappears and my objects are synchronized.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2019
    Hi @olistan,

    This looks like a bug yes.
    Can you replace line 2018 of "Assets\Photon\PhotonUnityNetworking\Code\PhotonNetworkPart.cs"?

    short remoteLevelPrefix = (pvUpdates[1] != null) ? (short)pvUpdates[1] : (short)0;

    with

    short remoteLevelPrefix = (pvUpdates[1] != null) ? (byte)pvUpdates[1] : (short)0;

  • Hi @JohnTube ,

    I can confirm that replacing (short) with (byte) fixes the issue. I have re-enabled the calls to SetLevelPrefix() and I'm not getting errors anymore.