You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UE5 C++编译报fatal error C1083找不到已有头文件如何解决

问题环境
  • 引擎版本:Unreal Engine 5.0.2
  • 开发工具:Visual Studio 2019
  • 项目名称:SandBox3
问题复现流程
  • 基于第一人称模板默认的SandBox3Character基类,创建名为NewCharacter的C++子类
  • 触发Live Coding手动重编译时编译失败
报错日志
Manual recompile triggered
---------- Creating patch ----------
Running E:\Editors\UE_5.0\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe -Target="SandBox3Editor Win64 Development -Project=""C:/Users/Uraking/Documents/Unreal_Projects/SandBox3/SandBox3.uproject""" -LiveCoding -LiveCodingModules="E:/Editors/UE_5.0/Engine/Intermediate/LiveCodingModules.txt" -LiveCodingManifest="E:/Editors/UE_5.0/Engine/Intermediate/LiveCoding.json" -WaitMutex -LiveCodingLimit=100
  Log file: C:\Users\Uraking\AppData\Local\UnrealBuildTool\Log.txt
  Building SandBox3Editor...
  Using Visual Studio 2019 14.29.30145 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
  [Adaptive Build] Excluded from SandBox3 unity file: NewCharacter.cpp, SandBox3.cpp, SandBox3Character.cpp, SandBox3GameMode.cpp, SandBox3Projectile.cpp, TP_PickUpComponent.cpp, TP_WeaponComponent.cpp
  Determining max actions to execute in parallel (6 physical cores, 12 logical cores)
    Executing up to 6 processes, one per physical core
  Building 2 actions with 2 processes...
  [1/2] Compile NewCharacter.gen.cpp
  C:\Users\Uraking\Documents\Unreal_Projects\SandBox3\Source\SandBox3\Private\NewCharacter.h(6): fatal error C1083: Cannot open include file: 'SandBox3Character.h': No such file or directory
  [2/2] Compile NewCharacter.cpp
  C:\Users\Uraking\Documents\Unreal_Projects\SandBox3\Source\SandBox3\Private\NewCharacter.h(6): fatal error C1083: Cannot open include file: 'SandBox3Character.h': No such file or directory
Build failed.

报错指向NewCharacter.h第6行无法找到SandBox3Character.h头文件,该头文件实际存放在文件上级目录,解决方案资源管理器结构参考:
解决方案资源管理器截图

错误原因

Unreal Build Tool(UBT)默认不会将头文件所在目录的上级目录加入头文件搜索路径,仅会默认加入当前模块的Public目录、当前编译源文件所在目录。新增C++类后如果未重新生成VS项目文件,或头文件存放不符合UE模块目录规范,就会触发该类找不到头文件的错误;另外Live Coding对新增类的首次编译存在已知缓存问题,也可能导致路径识别异常。

解决步骤

按优先级依次尝试以下操作:

  1. 重新生成项目文件
    • 先关闭Live Coding,关闭UE编辑器和Visual Studio
    • 右键项目根目录下的SandBox3.uproject文件,选择Generate Visual Studio project files,等待生成完成
    • 重新打开项目触发全量编译,不要直接用Live Coding编译新增的C++类
  2. 修正头文件存放路径,符合UE开发规范
    • 检查SandBox3Character.h的存放位置,第一人称模板默认该文件存放在Source/SandBox3/Public/目录下,该目录会被UBT自动加入搜索路径,直接写#include "SandBox3Character.h"即可正常引用
    • 如果该文件被误移动到了Private目录的上级(即Source/SandBox3/根目录和Public、Private文件夹同级),直接将其移动到Public目录即可,不要在include语句中写../形式的相对路径,避免后续调整目录结构时反复出现路径错误
  3. 清理缓存全量重编译
    • 如果以上操作后仍然报错,删除项目根目录下的Binaries、Intermediate、Saved三个缓存文件夹
    • 重新生成VS项目文件,打开编辑器做一次全量编译即可解决

内容的提问来源于stack exchange,提问作者Uraking

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 01:12:25