UnityWebGL异常捕获错误提示 An exception has occurred, but exception handling has been disabled in this build

Bug问题

webgl的项目中,偶尔会出现以下错误:
在这里插入图片描述
An exception has occurred, but exception handling has been disabled in this build. If you are the developer of this content, enable exceptions in your project WebGL player settings to be able to catch the exception or see the stack trace.

有道翻译后为:
发生异常,但在此生成中已禁用异常处理。如果你是这个内容的开发者,在你的项目WebGL播放器设置中启用异常可以捕捉异常或者看到堆栈跟踪。

Bug解决方案

将Enable Exceptions 从 None,改为
Explicitly Thrown Exceptions Only或者Full Without Stacktrace重新打包即可。
在这里插入图片描述

Bug排查

1.想法

想到项目中的打包设置的Publishing Settings中的Enable Exceptions异常输出被设置成了None,应该是跟这个有关。
在这里插入图片描述

2.手写bug

写一个简单的调用空物体的报错bug。

public class Bug : MonoBehaviour
{
    public GameObject obj;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            obj.transform.position = Vector3.zero;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            Debug.Log(obj.name);
        }
    }
}

挂到场景物体上,不给obj赋值.
在这里插入图片描述

3.unity运行

按A或S正常报错。
在这里插入图片描述

4.打包测试

分别以Enable Exceptions 为 None、
Explicitly Thrown Exceptions Only、Full Without Stacktrace三种情况打包。

5. 测试结果

None 出现提示框bug
Explicitly Thrown Exceptions Only 无提示框bug,web控制台检测到错误
Full Without Stacktrace 无提示框bug,web控制台检测到错误

谢谢阅读,如果对你有帮助可以给我点个赞,或者加个收藏,方便以后查看

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

真鬼123

祝你节节高升岁岁平安越来越漂亮

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值