Invalid Cast Exception Error : Right After Photon.Instantiate ?

Options
Hi Fellows,
I am getting error when Photon.Instantiate called. It is okay when i assing Photon.Instantiate group parameter as 0.
But if i do set group parameter differenly. I am getting InvalidCastException: Cannot cast from source type to destination type.
Output Below :
InvalidCastException: Cannot cast from source type to destination type. NetworkingPeer.DoInstantiate (ExitGames.Client.Photon.Hashtable evData, .PhotonPlayer photonPlayer, UnityEngine.GameObject resourceGameObject) (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3070) PhotonNetwork.Instantiate (System.String prefabName, Vector3 position, Quaternion rotation, Int32 group, System.Object[] data) (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2493) OnJoinedInstantiate.DoStuff () (at Assets/_External/Photon Unity Networking/UtilityScripts/OnJoinedInstantiate.cs:48) OnJoinedInstantiate.OnCreatedRoom () (at Assets/_External/Photon Unity Networking/UtilityScripts/OnJoinedInstantiate.cs:23) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2706) NetworkingPeer:GameEnteredOnGameServer(OperationResponse) (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1229) NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1797) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() PhotonHandler:Update() (at Assets/_External/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)

And thus command line cause error : inside internal GameObject DoInstantiate method.
byte group = 0; if (evData.ContainsKey((byte)3)) { group = (byte)evData[(byte)3]; }

have a nice work.

Best Regards ,
Oguzhan

Best Answer

  • OguzhanHalil
    Answer ✓
    Options

    Hi @OguzhanHalil,

    there is a little bug in the current PUN version which will be fixed with the next update. For now you can apply this fix yourself.

    Open PhotonNetwork class and look for all variants of the Instantiation function. These functions can be found (PUN version 1.84) in line 2435, line 2450 and line 2510. For each of this three functions look for the group parameter and change its type from int to byte.

    Now open the NetworkingPeer class and look for SendInstantiate function. In PUN 1.84 this function can be found in line 3001. Do the same like before and change the type of the group parameter from int to byte.

    Thanks for the reply. I will try that fix asap.

    Have a nice day.

Answers

  • Hi @OguzhanHalil,

    there is a little bug in the current PUN version which will be fixed with the next update. For now you can apply this fix yourself.

    Open PhotonNetwork class and look for all variants of the Instantiation function. These functions can be found (PUN version 1.84) in line 2435, line 2450 and line 2510. For each of this three functions look for the group parameter and change its type from int to byte.

    Now open the NetworkingPeer class and look for SendInstantiate function. In PUN 1.84 this function can be found in line 3001. Do the same like before and change the type of the group parameter from int to byte.
  • OguzhanHalil
    Answer ✓
    Options

    Hi @OguzhanHalil,

    there is a little bug in the current PUN version which will be fixed with the next update. For now you can apply this fix yourself.

    Open PhotonNetwork class and look for all variants of the Instantiation function. These functions can be found (PUN version 1.84) in line 2435, line 2450 and line 2510. For each of this three functions look for the group parameter and change its type from int to byte.

    Now open the NetworkingPeer class and look for SendInstantiate function. In PUN 1.84 this function can be found in line 3001. Do the same like before and change the type of the group parameter from int to byte.

    Thanks for the reply. I will try that fix asap.

    Have a nice day.