Version: Unity 6.3 Beta (6000.3)
Language : English
Set up your JavaScript plug-in
Call JavaScript functions from Unity C# scripts

Customize error handling

Choose how to handle errors in your Web builds.

Unity writes some JavaScript code to builds by default, which handles errors. This code displays warning messages when running on unsupported platforms and parses error and exception strings from the browser to check for known errors and display error dialogs with more comprehensive error messages. You can customize this handling, for instance, if you want to suppress the warning messages.

To customize error handling:

  1. Open the index.html file in your Web template.

  2. Add or uncomment the following code as a parameter in the var config = {} object:

      errorHandler: function(err, url, line) {
        alert("error " + err + " occurred at line " + line);
        // Return 'true' if you handled this error and don't want Unity
        // to process it further, 'false' otherwise.
        return true;
      },
    

The errorhandler function is called when the page invokes its window.onerror event handler and uses the same parameters. Return true from this function to signal that your error handler has processed the error, in order to suppress Unity’s default error handler from executing. Return false to pass the error to Unity’s default error handler to process.

Additional resources

Set up your JavaScript plug-in
Call JavaScript functions from Unity C# scripts
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961