Unity 报错之 Scope was not disposed! You should use the 'using' keyword or manually

191 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 6月更文挑战」的第14天,点击查看活动详情

Unity 报错之 Scope was not disposed! You should use the 'using' keyword or manually call Dispose.

发生错误

本地环境:

  • Mac版本:11.2.2
  • Unity版本:2019.2.0f1

导致报错的操作:

工程为Android平台,想修改游戏图标,点击了 Project Setting --> Player --> Default Icon

然后Player也没就不见了,并且点击报错,如下图:


报错信息

报错截图

详细信息

Scope was not disposed! You should use the 'using' keyword or manually call Dispose. UnityEngine.Scope:Finalize()

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

ArgumentException: GUILayout: Mismatched LayoutGroup.repaint UnityEngine.UIElements.UIR.RenderChain.Render (UnityEngine.Rect topRect, UnityEngine.Matrix4x4 projection) (at /Users/unity/buildslave/unity/build/Modules/UIElements/Renderer/UIRChainBuilder.cs:238) UnityEngine.UIElements.UIRRepaintUpdater.DrawChain (UnityEngine.Rect topRect, UnityEngine.Matrix4x4 projection) (at /Users/unity/buildslave/unity/build/Modules/UIElements/Renderer/UIRRepaintUpdater.cs:66) UnityEngine.UIElements.UIRRepaintUpdater.Update () (at /Users/unity/buildslave/unity/build/Modules/UIElements/Renderer/UIRRepaintUpdater.cs:54) UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTree () (at /Users/unity/buildslave/unity/build/Modules/UIElements/VisualTreeUpdater.cs:72) UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at /Users/unity/buildslave/unity/build/Modules/UIElements/Panel.cs:637) UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/unity/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:240) UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/unity/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:78) UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/unity/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)


解决方案

方法一:

切换平台:先切换到PC,在切换回来。然后编辑器就正常了。

实现方法:找到Build Settings面板 --> 选择PC --> 点击Switch Platform 然后等待切换完成,再切换回来。

方法二:

打安卓包:打包APK或者导出Android工程后,编辑器就正常了。

实现方法:找到Build Settings面板 --> 点击Export 或者 Build。 然后等待打包完成即可。

编辑器正常后:禁用 Metal Editor Support 会更改编辑器 API(重新启动 Editor),然后重新启用 Metal 支持(再次重新启动 Editor)和错误消失了。 在这里插入图片描述

其他方法

若你尝试了上述方法,那么可以看下面链接里的回答,尝试其他解决办法: 参考地址