当前位置: 首页 > news >正文

关于Unity的CanvasRenderer报错

MissingReferenceException: The object of type ‘CanvasRenderer’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.Canvas canvas, UnityEngine.Camera eventCamera, UnityEngine.Vector2 pointerPosition, System.Collections.Generic.IList1[T] foundGraphics, System.Collections.Generic.List1[T] results) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/GraphicRaycaster.cs:335)
UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List1[T] resultAppendList) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/GraphicRaycaster.cs:236) UnityEngine.EventSystems.EventSystem.RaycastAll (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List1[T] raycastResults) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:263)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.PerformRaycast (UnityEngine.InputSystem.UI.ExtendedPointerEventData eventData) (at Library/PackageCache/com.unity.inputsystem@1.4.4/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:271)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.ProcessPointer (UnityEngine.InputSystem.UI.PointerModel& state) (at Library/PackageCache/com.unity.inputsystem@1.4.4/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:315)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.Process () (at Library/PackageCache/com.unity.inputsystem@1.4.4/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:2112)
UnityEngine.EventSystems.EventSystem.Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)

先上报错问题。然后说一下我怎么遇到的问题,最后再说解决办法。
这个问题我是怎么遇到的呢,删除不用的UI,这里是一个功能模块的UI,比如你的程序的主页UI,删除后直接运行,当你的鼠标憋说点击了,放到UI上就会报上边的错误,跟你说GraphicRaycaster.Raycast检测不到你的UI了。或者说你的UI上没有CanvasRenderer了,问你是不是删除了,对,我是删除了,我tm在程序启动前删除的,反应迟钝把,这不得不让你想unity的缓存机制了。问题找到了,给你的感觉就是他缓存里你的东西还在,但是你删除了,出现的是这个问题。
一般情况出现这个问题比如说你已经删除了,但是找不到,说明有地方有残留,比如你的脚本上有对删除物体的引用,有对事件的注册等等,其实不一定非得是CanvasRenderer的missing的报错,其他组件有missing的报错都可以这么推理。不是你脚本上的问题,那么就是unity的缓存的问题。
接下来说一下我的解决办法:
直接删除你不要的UI,他还是报错怎么办?把unity关闭,然后重启
最后在说一下,出现这个问题的原因之一是你之前肯定看到了说你的UI预制体too large的红色报错了。

相关文章:

  • spring-tx笔记
  • 关于多目标进化算法评估指标
  • 可编辑52页PPT | 智慧园区安全生产顶层设计方案
  • 在C语言基础上学Java【Java】【二】
  • 工业软件的破局与重构:从技术依赖到自主创新的未来路径
  • Vagrant+VMWare 安装Ubuntu24.04
  • JVM常见概念之条件移动
  • 《掌握基础DOM操作:从零开始的前端入门指南》
  • C++的常用容器嵌套
  • Android Compose 基础布局之 Box 和 Stack 源码深度剖析(九)
  • 【留一下记录】Vllm在Linux环境下的学习笔记
  • 多路FM调频广播解调器:多路电台FM广播信号一体化解调处理方案
  • Burp Suite HTTPS解密原理
  • 星越L_大灯延时关闭使用讲解
  • vue3之写一个aichat---实现聊天逻辑
  • OpenCV Imgproc 模块使用指南(Python 版)
  • 【ACM竞赛的必要性】
  • 鸿蒙开发工程师简历项目撰写全攻略
  • 力扣刷题——143.重排链表
  • 如何利用环境监控看板提升工厂生产质量和效率
  • 上财发布“AI+课程体系”,人工智能如何赋能财经教育?
  • 湖南省职业病防治院通报3岁女童确诊“铊中毒”:去年病例,编辑误写为“近日”
  • 我驻苏丹使馆建议在苏中国公民尽快撤离
  • 哈马斯官员:进一步停火谈判毫无意义
  • 缅甸国防军继续延长临时停火期限至5月31日
  • 五一假期,新任杭州市委书记刘非到嘉兴南湖瞻仰红船