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.

InvalidCastException: Specified cast is not valid.Photon.Pun.PhotonTransformView.OnPhotonSerializeVi

2021-03-23 08:03:22

I'm getting this error on Pun 2.25

InvalidCastException: Specified cast is not valid.Photon.Pun.PhotonTransformView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformView.cs:125)Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:734)Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:724)Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1821)Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2192)Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3249)

OnPhotonSerializeView() writes and reads the data as expected. And have checked the types as well.
Here is my OnPhotonSerializeView() function

Unable to figure out what exactly is causing the error.


2021-03-23 09:36:44

Hi @SriharshaAntiz,

Thank you for choosing Photon and for your report!

Could you update to the latest PUN2 and retry?
When you try the PUN Basics Tutorial or Asteroids demos scenes that are provided in the package, can you reproduce?
Did you modify PhotonTransformView or any other PUN 2 code?

2021-03-23 13:08:04

Hi @JohnTube mod,

Thanks for looking in,

After updating the Photon these below errors are thrown.

Assets/Photon/Simple/Components/SyncState/SyncOwner.cs(213,28): error CS1061: 'PhotonView' does not contain a definition for 'SetOwnerInternal' and no accessible extension method 'SetOwnerInternal' accepting a first argument of type 'PhotonView' could be found (are you missing a using directive or an assembly reference?)

Assets/Photon/Simple/Core/NetMaster/NetMaster.cs(477,28): error CS1061: 'PhotonView' does not contain a definition for 'SetControllerInternal' and no accessible extension method 'SetControllerInternal' accepting a first argument of type 'PhotonView' could be found (are you missing a using directive or an assembly reference?)

I have tried to clear the errors, but I'm unable to, any help is much appreciated.

Thanks in advance :smile:

2021-03-23 19:22:56

Hi @SriharshaAntiz,

Simple is no longer included in PUN2 package.
You need to download it and import it separately on top of PUN2.
Read more here.

You can also remove it from your project if you don't use it.
Or clean it up before updating it.

Folders: "Assets\Photon\PhotonUtilities" and "Assets\Photon\Simple."

Thank you for your understanding and sorry for the inconvenience!

2021-03-24 06:52:29

Hi @JohnTube mod,

I have followed your instructions and cleared all the errors and was able to run the project, but the above error persists even after the update.

Error after update,

InvalidCastException: Specified cast is not valid.
Photon.Pun.PhotonTransformView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformView.cs:125)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:616)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:606)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1864)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2235)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3289)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:891)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:558)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1837)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:223)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:149)

To give an idea what i'm trying to achieve, I am trying to synchronise two players in my game and have done it using Photon's OnPhotonSerializeView() . The error occurs while running on unity editor, but bypasses it continues and both the players are shown (Player 1 runs on mac build and Player 2 runs on unity editor 2019.2.5f1)

But, the same is not reproduced on iOS devices. Able to view two players on only one device, the run device displays' its player alone.

I have tried it with simple function as below

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
if (stream.IsWriting)
else if (stream.IsReading)

Even without passing any stream writing and reading the error still occurs. Unable to figure out whether it is my coding mistake or a bug on Photon end.

Back to top