My game keeps crashing. Why?

I’ve tried rebuilding (a billion times), building for x86, rebooting my computer (twice), and excluding unfinished scenes from build. The game appears to still be running when I rebuild, and I have to end the UnityCrashHandler task from task manager. What else could be a possible solution?

P.S. I just tested: an older build doesn’t work (but I’m pretty sure it’s because I can’t connect to Discord right now, and it checks my rights to run the game via Discord GameSDK) and running it in play mode in the editor crashes Unity entirely, forcing me to reopen the project via Unity Hub. It’s likely some other program blocking it, but I couldn’t imagine what.

Alright, I did a little more digging. Playing Settings.unity from the editor works fine, it’s only MainMenu.unity (index 0 in build settings) that’s acting up. I’ll look further into what’s going on.

Always start with the logs. They may contain crucial information.

I’m unclear about what your problem is. Is the problem while building, or while running the build? If it is crashing, then it should have something in the logs. If it is still running, that doesn’t sound like a crash though. Are you sure you didn’t mean it is freezing? A freeze is usually caused by an infinite loop somewhere in your code.

I have debugged this scene to the moon and back. I have removed every single GameObject and it still crashes the game or editor. At that point, I figured maybe there was something wrong with the scene itself, not its hierarchy, and so I deleted the scene, made a new one, copied over the main parent GameObject, and played it, and the editor crashed.

That’s one of the first things I found in my initial Google search; the player logs don’t show anything useful, just some tech specs and XInput initializing. I checked editor logs too, but those didn’t contain much substance besides some packages not loading then being loaded later as well as Android and OSXStandalone modules not being found, but I’m not worried about that as I’m currently building for Windows Standalone.

I apologize for not being clearer; the issues occur when running the built game or entering play mode from the editor. The consequences, respectively, are the game exiting upon initialization or the editor completely closing (When I reopen the project, Unity Hub doesn’t say that the editor is already running). It’s possible that there may be an infinite loop, but off the top of my mind the only loop in my code is Update() from MonoBehaviour, I don’t even use coroutines or anything yet. Aside from checking my code (which I intend to do), is there any other way of debugging it and finding the cause of the problems?

Thank you all for your help.

Joe-Censored, I have checked my scripts as per your suggestion that it could be an infinite loop in my code. As far as I can tell, there’s nothing that should be endlessly running in without a player exploiting something, meaning there isn’t anything that could quit the game upon opening it.

Now that I think of it, I do recall recently adding a plugin for serialization. It’s open-source at GitHub - MessagePack-CSharp/MessagePack-CSharp: Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#], but it doesn’t seem that anyone else is having the same issue on Windows.

Does this happen in a new project?

1 Like

No; the described behaviour is not present in a fresh project with the same scene and assets relevant to it.

I’m still not clear if you’re referring to a freeze, where the application stops responding but stays up, or a crash, where the application unexpectedly exits.

Standalone build: game exits (but UnityCrashHandler keeps running until its task is ended)
Unity editor play button: Unity exits

What are the last lines in the Editor log immediately after this happens?

funny story. When I deleted the test project to achieve that conclusion, somehow I deleted my actual project too. After restoring it from recycle bin (thank god for that thing) and resolving a few GUID conflicts from previously deleted/renamed files, the scene works perfectly fine.

Thanks again for all your help; I apologize to anyone coming here in the future and not being able to find a solution aside from deleting and restoring your project.

not sure if this is the latest or if its what was wrong before but here it is:

[Package Manager] Server::Kill – Server was shutdown
##utp:{“type”:“MemoryLeaks”,“version”:2,“phase”:“Immediate”,“time”:1618471472903,“processId”:9284,“allocatedMemory”:501187,“memoryLabels”:[{“Default”:-3084},{“NewDelete”:122082},{“Thread”:167},{“Manager”:2584},{“Texture”:152},{“GfxDevice”:210584},{“Physics”:1},{“Serialization”:40},{“File”:16912},{“WebCam”:72},{“String”:44844},{“DynamicArray”:28466},{“HashMap”:23248},{“UTF16String”:42},{“Utility”:400},{“Curl”:-1728},{“PoolAlloc”:176},{“Sprites”:8},{“GI”:336},{“VR”:1888},{“Secure”:2024},{“Subsystems”:96},{“EditorGui”:2056},{“EditorUtility”:3200},{“AssetDatabase”:5498},{“AssetImporter”:32},{“RestService”:144},{“License”:10656},{“UnityConnect”:26368},{“Collab”:779},{“Licensing”:3144}]}

Should look into using some kind of source control.

2 Likes

Seriously, it is 2021. Use source control. If it’s worth doing, it’s worth backing up.

Personally I use git because it is free and there are tons of tutorials out there to help you set it up.

Here’s how I use git in one of my games, Jetpack Kurt:

https://discussions.unity.com/t/807568/3

Using fine-grained source control as you work to refine your engineering:

https://discussions.unity.com/t/826718/2

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up the right .gitignore file:

https://discussions.unity.com/t/834885/5

I am; I just hadn’t committed/pushed the latest changes.

1 Like

Thanks, I’m already using GitHub (you can check out my personal profile JuhJuhButts, I’m a big open-source advocate ). Nonetheless, I’ll take a look at these resources.

Did you find out what was the cause of your crash? Was it because of Discord Game SDK?