实际情况是这样,有一个List objs , for循环遍历这个objs,在循环内有一个判断当前元素是否存在组件,然后做一些Dotween的动画,代码如下
for (int i = 0; i < childNode.childCount; i++)
{
//排除自身
var t = childNode.GetChild(i).GetComponent<Test>();
{
if (t == dragComponent.GetComponent<Test>())
{
continue;
}
if (t.GetComponentInChildren<LiquidVolumeFX.LiquidVolume>())
{
t.GetComponent<Test1>().SimulateFallInContainer(bottomPos.y, 1.2f);
}
else
{
Vector3 b;
if (t.GetComponent<Collider>())
{
b = t.GetComponent<Collider>().bounds.size;
}
t.GetComponent<Test1>().SimulateFallInContainer(bottomPos.y+b.y / 2, 1.2f);
}
}
}
SimulateFallInContainer方法中是一段Dotween的动画。
结果是没有报Error,然后代码调试进入了Update区,使用捕获异常也没有打印。
这里不得不说一个坏习惯,有时候项目很大,喜欢把控制台的Warning关了。。
实际上这里有一个警告
DOTWEEN ► An error inside a tween callback was taken care of Object reference not set
原因是代码中的t 出现了空引用,为null,这个异常出现在了DOTween回调里,所以不会被当作error抛出,只是当做了Warning,但实际上报错了之后会影响一些逻辑,不能继续了,所以这里很容易被大家忽略,一定要注意。