Search Unity

Unity crashes when changing scenes...

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by BubyMB, Aug 24, 2016.

  1. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Hey guys, I am having a problem where unity crashes whenever changing scenes, this happens in a built version as well..

    This is my game manager script (in lobby)
    http://pastebin.com/shVGMFpN

    and this is my manager in the actual game
    http://pastebin.com/FWLVdrxZ

    I have tried turning the assets off then enabling them when i join a game so it does not stress the pc as much (Line 76), but it still crashes
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    2,899
    What does the log say , if its running out of memory it will tell you there.
     
  3. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    It can't be memory, I am looking at my task manager while doing it and still running at 60% with a bit of a spike.
     
  4. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    Your problem is here:
    1. void Update () {
    2. playButton.onClick.AddListener (delegate {this.ButtonClicked ();});
    3. PhotonNetwork.player.name = userBox.text;
    4. }
    Line #2 is Adding a Listener to the button cilck. This code should be in Start. Right now every update your adding an ADDITIONAL listener. So I suspect by the time you finally click that button. there are 100s of listeners all of which call the load level funcdtion. You only want that listener added once.

    Also I noticed userBox is a Text UI element. I assume its the Text Element of an InputField somewhere? You also don't want this being constantly updated in the Update function. Create a new function called UpdatePlayerName, and set the InputField's EndEdit Event to point to it.
     
  5. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Thanks, worked perfectly. I now see my mistakes, making the on click stack like that would make it open the scene hundreds of times
     
unityunity