Unity构建游戏时反复抛出CS0246错误求助
Unity编译错误:找不到PenStatus类型的解决办法
报错信息:
Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\EventData\PointerEventData.cs(235,16): error CS0246: The type or namespace name 'PenStatus' could not be found (are you missing a using directive or an assembly reference?) Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\UIElements\PanelEventHandler.cs(391,20): error CS0246: The type or namespace name 'PenStatus' could not be found (are you missing a using directive or an assembly reference?) Error building Player because scripts had compiler errors Build completed with a result of 'Failed' in 51 seconds (51127 ms) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)ds.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in :0 at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in :0 UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
解决步骤:
- 检查Unity版本与UGUI包兼容性:
PenStatus是Unity 2022.x及以上版本引入的类型,若使用旧版本引擎,UGUI包版本可能不匹配。打开Package Manager,找到com.unity.ugui,切换到与当前引擎匹配的版本。 - 重建UGUI缓存:删除项目目录下的
Library/PackageCache/com.unity.ugui@1.0.0文件夹,重启Unity,让引擎自动重新下载并导入正确的UGUI包文件。 - 验证平台输入模块:打开Unity Hub,找到当前使用的Unity版本,点击右侧三个点→添加模块,检查是否勾选了对应平台的笔/触控支持模块(比如Windows平台的「Windows Pen and Touch Support」),该类型依赖这些模块。
- 重置项目设置:在编辑器中依次点击
Edit → Project Settings → Editor,找到「Reset All Settings」选项,重置后重新尝试构建。
内容的提问来源于stack exchange,提问作者Nasir
相关产品推荐
相关产品推荐

