How to add a simple .h file from Visual Studio 2022 without breaking the compilation

Hi,

I’m new to Unreal Engine development in C++. After following all the basic tutorials without too much issues, i’m now trying to follow more tutorials.

I’ve just setup and installed:

  • Unreal Engine 5.2.1
  • Visual Studio 2022 Preview 17.7 build 3. It’s supposed to better handle unreal macros formatting now.

I created a 3D Third person project with content as a c++ project and I opened it in Visual Studio 2022. So far so good : project is compiling well, and everything seems to work.

Now here comes my basic problem, I now try to create a simple header file with some structs inside. And doing this breaks the whole project.

Here is how i reproduce the problem :

  1. Add new item…
    By default the item location suggested by VS is inside “Intermediate” folder. I know by googling that this is definitely not ok. So it should be in the Source Folder.

  2. So I decided to create the .h file in a new Source “subfolder” (yeah… subfolder : Source/Public/Data ) :

  3. Now my file is visible in the editor, even though folder structure is not visible.
    image

  4. To solve this, I followed some advices and quitted the editor, delete the whole Intermediate, Saved folders and InventoryTutorial.sln from windows explorer and have them generated again using right click “Generate Visual Studio project files” to refresh the whole VS project structure:
    image

  5. Files are re-generated well. By launching Visual Studio 2022 again, I can now see my project and proper file structure for my newly created header file :

  6. Here is my problem : project doesn’t compile anymore, even tough my header file is quite basic :

Project has 4783 errors, the first ones are :

Severity Code Description Project File Line Suppression State
Error (active) E1696 cannot open source file UBT_COMPILED_PLATFORM/UBT_COMPILED_PLATFORMPlatform.h InventoryTutorial D:\epic\Epic Games\UE_5.2\Engine\Source\Runtime\Core\Public\HAL\Platform.h 126

It seems that creating a header file from Visual Studio Editor in a subfolder breaks the whole project.

I found 2 workarounds but not good enough to me :

  • Workaround 1 : Create all my files in the same directory (not a good developer’s practice)
  • Workaround 2 : Always create my header files through Unreal Editor. (New class… no parent)…

When using workaround #2, then I need to delete the Private folder created (cpp file) as i don’t need it for my struct. Then unreal can compile the whole project. Though Visual Studio Editor loses all the intellisense for this header file.

I’m new to Unreal / C++ development and I’m sure I must have understood something wrong. Can you help me understand why my build/intellisense fails and what is the proper way to work with Visual Studio 2022 and create subfolders and header files easily when developing in Unreal Engine ?

This is the intended way of creating c++ files in Unreal, not a workaround.


If you don’t want to add files from Unreal, You can use Rider instead of Visual Studio. Rider has a button built in to create Unreal Classes correctly. Rider also supports all of the Unreal specific macros and stuff.

It’s paid, but there’s a 1 month free trial. There’s also an Early Access Program which is basically free :

Hi @Extrone thanks for your quick answer !

I can understand that creating files from UE editor is the intended way… Though, when I do that and create choose to create file in a subfolder (Let’s say Source/Public/Data/MyFile.h), then I obtain this bunch of errors in visual studio and not more intellisense, even though live compilation works:

I think this is not intended and there must be some configuration missing on VS studio project files because “Source” sub-folders should also work with VS 2022 editor.

Any clue about these errors ?