PhotonNetwork.Instantiate Error.

Hi,

I'm currently working on adding Photon Cloud to our new game. First of all I must say how easy its been to get multiplayer working. But I'm currently having one issue.

I'm setting a 1v1 match, I connect the players in a lobby scene and then when both are ready. I load the game scene, I then each client Instantiates a car.

But I'm getting an error, for the local Instantiate and the remote one too. When running on iOS this kills the app, but in the editor and running standalone the error still happens but the game continues to run and the multiplayer works fine.

I can't seem to find why its happening, I've been trying to debug it all day :(

Any help will be a massively appreciated.
Regards,
David.

Here are the two error messages from the editor -

NullReferenceException: Object reference not set to an instance of an object
NetworkingPeer.GetCachedMethod (UnityEngine.MonoBehaviour monob, PhotonNetworkingMessage methodType) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2881)
NetworkingPeer.DoInstantiate (System.Collections.Hashtable evData, .PhotonPlayer photonPlayer, UnityEngine.GameObject resourceGameObject) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1813)
PhotonNetwork.Instantiate (System.String prefabName, Vector3 position, Quaternion rotation, Int32 group, System.Object[] data) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1193)
CarSpawner.Start () (at Assets/GameSetup/CarScripts/CarSpawner.cs:67)

NullReferenceException: Object reference not set to an instance of an object
NetworkingPeer.GetCachedMethod (UnityEngine.MonoBehaviour monob, PhotonNetworkingMessage methodType) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2881)
NetworkingPeer.DoInstantiate (System.Collections.Hashtable evData, .PhotonPlayer photonPlayer, UnityEngine.GameObject resourceGameObject) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1813)
NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1354)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:65)

Comments

  • For some reason, the DoInstantiate call fails. This should create the actual game object but fails, cause some method is not cached yet.
    I assume you use PUN 1.17? I'll take a look at NetworkingPeer.cs:2881.

    If you load scenes, make sure to disable the message queue, as described in "Unity3d and PUN":
    http://doc.exitgames.com/photon-cloud/C ... references

    For matchmaking: It's rarely necessary to let players meet in some room. You can use random matchmaking and create a room if needed:
    http://doc.exitgames.com/photon-cloud/M ... references
  • I don't know yet exactly why this fails but as workaround you could add a null-check into GetCachedMethod():
    if (monob == null) return null;

    I wonder if you could send me reproduction code to [email protected]?
  • Tobias wrote:
    I don't know yet exactly why this fails but as workaround you could add a null-check into GetCachedMethod():
    if (monob == null) return null;


    Thanks I can confirm that just adding that line worked no errors :)
  • I'm still interested in understanding what you do to cause it.
    If you send a project or part of that, it's of course treated as you secret.