The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

invalid cast exception

2022-08-28 22:47:53

i am getting this error

InvalidCastException: Specified cast is not valid.

Photon.Pun.PhotonTransformViewPositionControl.DeserializeData (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformViewClassic.cs:390)

Photon.Pun.PhotonTransformViewPositionControl.OnPhotonSerializeView (UnityEngine.Vector3 currentPosition, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformViewClassic.cs:368)

Photon.Pun.PhotonTransformViewClassic.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformViewClassic.cs:128)

Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:544)

Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:534)

Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1862)

Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2233)

Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3364)

ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/PeerBase.cs:899)

ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/EnetPeer.cs:583)

ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/PhotonPeer.cs:1771)

Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:226)

Rethrow as AggregateException: Caught 1 exception(s) in methods called by DispatchIncomingCommands(). Rethrowing first only (see above). (Specified cast is not valid.)

Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:244)

Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:145)


2022-08-29 13:09:13

This likely happens because your observed components on a prefab send something else than they expect or read. Make sure that the values you send (from controller) are expected in that order...

This should not happen in the default PhotonTransformView. Maybe you modify the prefab instance for the clients that are not in control of the object?

2022-08-30 00:57:06

i figured it out i was using PhotonTransformViewClassic instead of PhotonTransformView, i think thats what caused it

2023-06-08 13:12:59

hi guys, i was having the same error, but im not using PhotonTransformViewClassic, i was using default PhotonTransformView. i tried to check the error on the PhotonTransformView script and add some try-catch on the line that was shown in the error and managed to get some info. somehow the PhotonTransformView was trying to cast -1 to vector3 which is invalid, do you know why i get -1? AND also this error was preventing me to get PhotonAnimatorView Synced and it was frustrating. Please help me.

Here's some screenshoot of the error, also some screenshow of the changes that i made in PhotonTransformView.cs script

Back to top