Custom error messages

Monetizr plugin is designed to fail silently. But sometimes it might be valuable to display an error message to your users to reduce confusion or while doing tests.

The plugin provides a simple built-in alert screen. It's intended to be used for testing purposes. By default this screen is disabled and can be enabled with a toggle on the Monetizr prefab.

Built-in alert pageBuilt-in alert page

Built-in alert page

Using a custom alert screen

The main Monetizr object that's accessible with MonetizrClient.Instance provides a delegate that you can subscribe to. The subscriber methods are required to have a single string argument. This delegate is called when plugin internally logs an error though it is also possible to display your own errors with MonetizrClient.Instance.ShowError(string).

using Monetizr;

//Example subscription to delegate
public void HandleError(string error_msg) {
    //Do something with error_msg
    Debug.LogWarning(error_msg);
}

//At some point in your script you need to subscribe to the delegate
private void Start() {
    MonetizrClient.Instance.MonetizrErrorOccurred += HandleError;
}

//And you need to unsubscribe if this object is being destroyed, otherwise error-ception will occur
//OnDestroy is automatically called by Unity, similar to Start or Update
private void OnDestroy() {
    MonetizrClient.Instance.MonetizrErrorOccurred -= HandleError;
}

If you're not familiar with delegates in C# here is a tutorial by Unity to get your started!


Did this page help you?