Unity Crashes on Play

Things seemed to be going fine in the beginning but after completing further lessons, I get crashes on Play similar to Unity crashes on play

Not sure if it’s due to things I’ve added (likely) or some bugs or general Unity pain with race conditions in the Scene Loader type stuff (also likely). I’ve encountered this elsewhere in my game while managing Scenes: especially adding them additively. In this case it’s just a single Scene though.

I’ve disabled the saving system for now as my hair was starting to run out. Deleting the sav file in %appdata% LocalLow\DefaultCompany<Your Game Name> would sometimes help but eventually things would go sideways.

I’ll check back here with more info if the bug gets solved later in the course or if I figure it out…

You should be able to find the Editor.Log file in the same directory as the Save file whenever Unity decides to crash. This can be useful, combined with clever Debug.Logs to determine where the crashes might be coming from.
9 times out of 10, the source of the crash is uncontrolled recursion… something calling itself over and over… a great example, and something that every programmer has done by accident at least once involves getters and setters…

private int myVariable=1;
public int GetMyVariable()
{
    return GetMyVariable(); //should be return myVariable
}

While this example seems a bit obvious, it’s more common when using properties, as it’s common syntax to have the underlying field be lower case and the property capitalize the name:

private int myVariable=1;
public int MyVariable
{
     get
     {
          return MyVariable;
     }
}

That one is more subtle, and happens often because Intellisense tricks us and sometimes autocompletes as MyVariable instead of myVariable. It’s a lot harder to spot than GetMyVariable();

1 Like

Privacy & Terms