关于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的红色报错了。

相关推荐
ttod_qzstudio1 小时前
Unity中使用EzySlice实现模型切割与UV控制完全指南
unity
南無忘码至尊2 小时前
Unity 实现与 Ollama API 交互的实时流式响应处理
unity·游戏引擎·交互
平行云5 小时前
如何实现UE程序大并发多集群的像素流部署
unity·ue5·图形渲染
mit6.82418 小时前
[shad-PS4] Vulkan渲染器 | 着色器_重新编译器 | SPIR-V 格式
c++·游戏引擎·ps4
向宇it1 天前
【unity小技巧】在 Unity 中将 2D 精灵添加到 3D 游戏中,并实现阴影投射效果,实现类《八分旅人》《饥荒》等等的2.5D游戏效果
游戏·3d·unity·编辑器·游戏引擎·材质
向宇it1 天前
Unity Universal Render Pipeline/Lit光照材质介绍
游戏·unity·c#·游戏引擎·材质
__water2 天前
RHA《Unity兼容AndroidStudio打Apk包》
android·unity·jdk·游戏引擎·sdk·打包·androidstudio
不爱说话的采儿2 天前
UE5详细保姆教程(第四章)
笔记·ue5·游戏引擎·课程设计
温玉琳琅2 天前
【UE5】虚幻引擎小百科
ue5·游戏引擎·虚幻
两水先木示2 天前
【Unity3D】微信小游戏适配安全区域或胶囊控件(圆圈按钮)水平高度一致方案
unity·微信小游戏·安全区域·ui适配·胶囊控件·safearea