RPC Error - Cannot cast from source type to destination type

I've been using Unity3D for a few months now, and got pretty good with their networking. I actually wrote a very popular Unity3D Networking eBook http://www.3dmuve.com/3dmblog/?p=201. I've received rave reviews on the eBook which I'm very proud of, but I recently discovered some limitations with the native Unity3D networking that will be a problem for my current project. Based on what I've read I believe Photon will resolve these issues, but first I need to get my current project ported over to properly test it.

I just ported the code last night using the converter and after a little tweaking I got a clean compile and have it running. However, immediately after I instantiate my first Network.Instantiate prefab I then call an RPC and the RPC is failing with "Cannot cast from source type to destination type".

This worked perfectly under the legacy Unity3D networking.

I'm doing:
    GameObject newplayer = PhotonNetwork.Instantiate( PlayerCraft, _spawn.transform.position, _spawn.transform.rotation, 0) ; PhotonView _pv = (PhotonView)newplayer.GetComponent("PhotonView"); _pv.RPC("mycommand", PhotonTargets.AllBuffered, (int)LocationID);

I'm getting this error getting my scene up and running:
    InvalidCastException: Cannot cast from source type to destination type. NetworkingPeer.ExecuteRPC (System.Collections.Hashtable rpcData, .PhotonPlayer sender) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1445) NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2316) PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1489) PhotonView.RPC (System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/Extension/PhotonView.cs:219) Instantiate.InstantiatePlayerOnLoadedLevel (Int32 _QuadrantId) (at Assets/Pulsar/PulsarCode/Networking/Instantiate.cs:20) NetworkLevelLoad+<CoLoadLevel>c__Iterator0.MoveNext () (at Assets/Pulsar/PulsarCode/Networking/NetworkLevelLoad.cs:84)

Any Help greatly appreciated.



  • Tobias
    It looks like a known issue for Level Prefix. I planned to replace the 1.17 version but then got distracted by refactoring the viewID assignment and improving other parts.

    The solution is simple, so please apply this fix:

    Alternatively, I can only encourage you to use the preview of PUN 1.18. It's not perfect yet but several developers use it successfully and I would appreciate feedback.
  • Thanks Tobias, that worked. I saw that and was going to change it, but thought no,

    A. It couldn't be that easy and

    B. I didn't want to mess with Photon code just my own. Good to know I can do this and will keep my eye out for other such issues.

    As for knowing what version I'm on and how to get a dev build, what do I do? I'm using the most recent version for download but I wasn't actually sure of the version.

    Thanks again

  • Tobias
    To find your current PUN version, check: PhotonNetwork.versionPUN.
    We change this string per release (not necessarily per preview).

    It's usually good not to mess around with the PUN framework too much. It makes updates a bit harder and might break stuff at places you didn't expect, as it's not exactly fully documented. But we think it's a good idea to provide the source for reading and for doing small adjustments.