Log Unity Exceptions with Raygun4Unity Beta

Jason FauchelleProvider UpdatesLeave a Comment

Today we are pleased to announce the beta of Raygun4Unity – first class support for sending error information from Unity games to Raygun.io. This supports Windows desktop, Windows Phone, Mac, iOS and Android.

log Unity exceptions

Once your game has been released to the world, the last thing you want to hear is that players have been having a bad experience due to crashes and bugs. What’s even worse is trying to work out how to reproduce these bugs and solve them. By integrating Raygun4Unity into your game, you’ll get information about all unhandled exceptions logged straight to your Raygun.io dashboard. This gives you loads of information that can be used to track down and fix bugs. Additionally, you won’t need to rely on the community to learn about what issues have occurred. All exception occurrences will be displayed in your dashboard giving you a view of the overall health of your game. Information can be filtered and searched, and the charts will plot the improvement of your game as you release patches or new versions.

Unity Exceptions

How to use Raygun4Unity

To get Raygun4Unity, head over to the latest release listed in GitHub and download Raygun4Unity.zip. Extract the contents, and paste the Raygun4Unity folder somewhere in the Assets directory of your Unity game. (When the first version of Raygun4Unity is released, we’ll look at providing it through the Unity assets store).

Now you can use Raygun4Unity to send exception information to Raygun.io. To do this, simply create an instance of RaygunClient by passing in your application API key into the constructor, then call one of the RaygunClient.Send methods.

(You get an API key when you create a new application in your Raygun.io account. The key is displayed in the setup instructions page, and can also be found in the application settings).

Odds are that you already have a central place in your game where you at least log exception information out to a file. If so, this is a great place to send the exception information to Raygun from. If however you don’t currently catch unhandled exceptions in your game, a common way to do this is to listen to Application.RegisterLogCallback. In the following example, Application.RegisterLogCallback has been set up in a MonoBehaviour that could be run during the initialization process of the game. The handler provides the message and the stack trace that can be sent in one of the RaygunClient.Send methods. Here you can see I’m checking the type of the log message so as to only send exceptions and errors, but you could send other log messages too.

Sometimes you may want to send information about handled exceptions – ones that aren’t critical to the game, but you may be interested in how often they occur, along with information about how to solve them. This can be done by sending the Exception object from within a try/catch block.

Overloads of the Send method allow you to send a list of tags or/and a dictionary of custom data. These can be set however you like and can be a huge help to debugging. You could use this to send the values of useful local variables, the state of the current player, or information about the loaded level.

Application Version

Knowing which version of your game each exception came from can help determine if an exception has already been resolved in a more recent version. Exceptions can also be filtered by version on your Raygun.io dashboard. To use this feature, set the ApplicationVersion property of the RaygunClient instance that you are using to send exception information.

User tracking

All the Raygun.io providers allow you to optionally specify user information which gives you an idea of the impact of each type of exception. When viewing information about an exception in Raygun.io, the number of users that were affected by that exception will be displayed. You could use this to prioritize which bugs to invest time into solving first. It’s easy to specify the user information by setting the UserInfo property of the RaygunClient instance. What information you provide is up to you, but it could include a name, email address or some kind of unique identifier, possibly from a database.

Get Raygun4Unity now

Once Raygun4Unity is set up in your game, all unhandled exception information will be logged to your Raygun.io dashbaord. This information includes as much of the stack trace that’s available, the screen resolution, the loaded level name, information about the platform that the game is running on, the graphics device, the device locale and of course any custom data that you’ve provided.

Unity Exception Instance

If you’re working on a Unity game project, we recommend trying out the beta of Raygun4Unity to give you awareness of the health of your game out in the wild. If you have any questions or feedback about it, we’d love to hear from you in the forums.

If you haven’t already, get started for free with a 30 day trial and see how Raygun can improve your Unity game development.

Next level software intelligence across your entire stack.

Leave a Reply

Your email address will not be published. Required fields are marked *