Basically, all I want is something for my game that reports crashes like the crash reporter that already exists for UnityEngine itself! Bringing up a dialogue box, then a nice little form for the user to email the crash report, and also generating a text file like UnityEngine does in that crashes folder. But, if no one knows how to do that, the next best thing is to ask questions about the smaller steps. So: Does anyone know how to make some code that can run when my Unity game crashes and run anyway? I can’t seem to find any information about this online and I’m looking to do any (or all) of these three things:
- Have some code that can run when my game crashes that will generate a text file about the crash ***(I have found a way to partially do this, but I have some questions that reading documentation or googling have been unable to answer to really call this “finished”)
- Emails this text to my email
- A dialogue box that lets the player know about the crash and gives them the option to email it
Help would be much appreciated because this is for a school competition!
***(CODE FOR EVERYTHING DESCRIBED FROM HERE ON OUT ATTATCHED BELOW): About the text file, using an event that subscribes to Application.logMessageRecieved (article on how to do that here: Unity - Scripting API: Application.logMessageReceived )
When I force a crash with a button that simply runs UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.FatalError),
the logMessageRecieved event is called, and I can output the error information, which is in the “logString” in the Unity article linked to above, to a textfile. The next thing I noticed is that I can make it so that, at least for my project, which has a lot of Debug.Log’s and missingreferenceexceptions, it only ouputs a crash to this file if I use an if statement that checks that the LogType (again check the unity article above) is LogType.Error. So, then I realized: If all errors result in a crash, or if all crashes are sent in the log as errors, that means that my code will be able to detect any sort of crash with this if statement. However, again, this is only true IF AND ONLY IF all errors result in crashes. So, for the last question/request of this post: is that statement true? Is anything that is a LogType.Error result in a crash?
I’ve attatched the script of what was just described. The only other thing you’d have to do is set up a button that runs UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.FatalError) on click to get a project identical to mine
CatchCrashScrript.cs (920 Bytes)