Documentation - Raygun4Unity - Unity Error Monitoring & Crash Reporting

Raygun4unity allows you to setup real time error monitoring and crash reporting for your Unity games.  

Setup instructions

1. Download the library

Download raygun4Unity.zip from the latest release listed on Github. Extract the contents and paste the raygun4Unity folder somwhere into the Assets directory of your game.

2. Listen to RegisterLogCallback

If you haven't done so already, listen to Application.RegisterLogCallback in a C# script. Attach this script to a GameObject that will be used when your game is loaded.

3. Use the RaygunClient to send exception reports

In your RegisterLogCallback handler (or any part of your game that listens to unhandled exceptions), create an instance of the RaygunClient by passing your API key into the constructor, then call one of the Send methods. Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings.

public class Logger : MonoBehaviour
  void Start ()

  private void HandleException(string message, string stackTrace, LogType type)
    if (type == LogType.Exception || type == LogType.Error)
      RaygunClient raygunClient = new RaygunClient("OIxvu7YKU4erOuQ791Q4HQ==");
      raygunClient.Send(message, stackTrace);

WARNING RegisterLogCallback can only have one handler at a time, so if you already are using RegisterLogCallback, then you'll want to send the exception information to Raygun.io within your existing callback.

Unique user tracking

To keep track of how many users are affected by each exception, you can set the User or UserInfo property of the RaygunClient instance. The user can be any id string of your choosing to identify each user. Ideally, try to use an id that you can use to relate back to an actual user such as a database id, or an email address. If you use an email address, the users gravitars (if found) will be displayed on the Raygun.io error dashboards. Below is an example of setting the User property:

raygunClient.User = "user@email.com";

The UserInfo property lets you provide additional user information such as their name:

raygunClient.UserInfo = new RaygunIdentifierMessage("user@email.com")
  IsAnonymous = false,
  FullName = "Robbie Robot",
  FirstName = "Robbie"

Here are all the available RaygunIdentifierMessage properties. The only required field is Identifier.

  • Identifier is the unique identifier from your system for this user.
  • IsAnonymous is a flag indicating whether the user is logged in (or identifiable) or if they are anonymous. An anonymous user can still have a unique identifier.
  • Email The user's email address. If you use email addresses to identify your users, feel free to set the identifier to their email and leave this blank, as we will use the identifier as the email address if it looks like one, and no email address is not specified.
  • FullName The user's full name.
  • FirstName The user's first (or preferred) name.
  • UUID A device identifier. Could be used to identify users across devices, or machines that are breaking for many users.

Tags and custom data

A couple of Send method overloads allow you to attach a list of tags and a dictionary of key-value custom data to the exception report. Tags and custom data get displayed on each report in Raygun. Either of these can be null if you only want to send one or the other.

The following overload is for when sending the message and stacktrace strings as provided by Unity in the HandleException callback.

var tags = new List() { "Level 6", "0 lives"};
var customData = new Dictionary() { {"Difficulty", "Very-Hard"} };
raygunClient.Send(message, stacktrace, tags, customData);

Another overload is available for when sending a .NET Exception object.

var tags = new List() { "Level 6", "0 lives"};
var customData = new Dictionary() { {"Difficulty", "Very-Hard"} };
raygunClient.Send(exception, tags, customData);

Game version

The current version of raygun4Unity does not automatically obtain the game version number. You can however specify this by setting the ApplicationVersion property of the RaygunClient instance.

raygunClient.ApplicationVersion = "";

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.