PhotonNetwork.ConnectUsingSettings crashes unity after reset. Help please?

Options
Hi everyone.

I have a rather specific problem and I hope someone might be smarter than me at solving it. :/
What I intend to do is a very basic reset of my entire game I created with unity c#.

In the first load of the game all works fine. Game is fully playable and all networking runs smoothly.


I have an empty main scene that only contains one single START-button that calls this script:
public void Startgame () { Application.LoadLevel ("Game"); }

That is the only code that exists in that scene.
In the game scene I have the root GameObject on stage with the MatchMaker script on it, which calls this:

// Use this for initialization void Start () { //DontDestroyOnLoad (this.gameObject); // <------ INACTIVE! Is destroyed on loadLevel Debug.Log ("PHOTON connection initialized"); PhotonNetwork.logLevel = PhotonLogLevel.Full; PhotonNetwork.ConnectUsingSettings ("0.2"); Debug.Log ("Arrives here"); } public override void OnConnectedToMaster () { Debug.Log ("PHOTON lobby joined"); PhotonNetwork.JoinLobby (); } public override void OnJoinedLobby () { Debug.Log ("PHOTON random room joined"); PhotonNetwork.JoinRandomRoom (); }


This works perfectly fine in the first run.

Now when I press the RESET button I created it jumps back to the initial MAIN scene that only has the button.
void ResetGame (BaseEventData trigger) { //Application.LoadLevel ("Main"); photonHandler.Unsubscribe (); PhotonNetwork.Disconnect (); GameObject[] GameObjects = (FindObjectsOfType<GameObject> () as GameObject[]); for (int i = 0; i < GameObjects.Length; i++) { Debug.Log ("GameObject destroyed: " + GameObjects [i].name); Destroy (GameObjects [i]); } Application.LoadLevel ("Main"); }

As you can see I disconnect from the server, kill all GameObjects and remove the only event I added, as you see below.
public void Unsubscribe () { Debug.Log ("Unsubscribe"); PhotonNetwork.OnEventCall -= this.OnEvent; }


Now my problem starts.
When I press the START button again, the GAME scene loads, but nothing happens after calling PhotonNetwork.ConnectUsingSettings ("0.2");

All the "On-whatever" are never called.

I traced a bit inside the ConnectUsingSettings and could only find one small difference between the first call that works, and the second call that does not work and I have no idea if that is of any significance.
It is simply that in the first call IsUsingNameServer is false, and on the second run it is already true, which seems to mean that the connection.... remembers somehow?



Anyway, when the code stops at that call nothing farther happens, no matter how long I wait.
But then this is on:
When I stop the script (Press the play button again) I can still click on anything, look at anything and use unity as intended. But as soon as I try to run the script again OR if I try to close Unity, it crashes so badly, that I have to call the task manager to be able to close it. Every single time. Very reliable crash.

Does anyone have any ideas what I should look for?

Comments

  • vadim
    Options
    Everything is ok with IsUsingNameServer. If you use nameserver, it set once and never changes.
    So what is the crash? Do you have any errors and stack traces in logs?
    Probably deleting all objects manually is not best idea. Why do you need that?
  • Thanks for your reply. :)

    And originally I needed to remove all GameObjects because somehow not all where cleared when I did Application.LoadLevel but you know what..... I just took out the manual remove to be able to tell you exactly what goes wrong when I don't have it... and now it all works.

    It all works perfectly and the only part I kicked out was the manual deletion of all GameObjects.

    You, Sir, are a wizard!
    Thx! ^^
  • Though I don't really understand what the real difference is. OnLoadLevel kills all the gameobjects just the same, does it not?
  • vadim
    Options
    LoadLevel does not destroy objects with DontDestroyOnLoad property set to true. PUN may use such objects to keep internal thing running.