unreal 4 – UE4 C++ – Add generated source code folders to Visual Studio solution?


In Unreal Engine 4, using a Visual Studio solution and projects generated from the Editor using the First Person Template, the layout of the Solution looks something like the following:

Solution Explorer Screenshot

I am not a fan of this flat horizontal folder structure. What I would like to do is put some new classes into a nested folder here.

I will be generating a new GameState subclass, and putting the sources into the SourceGameState folder that will also be created on the fly, using the UE4 editor:

UE4 Editor create new  c++ class

Notice that the “Create New Folder” option is disabled.

Added GameState folder

Here I have appended the “GameState” folder to the normal source path.

However, the folder structure in the Solution Folder has not changed, and nothing I try to do is working. The things I have tried to do so far include:

  • Drag the folder into the solution from the file explorer
  • Right Click > Add > Existing Item… (Which just results in the files appearing horizontally to the other files without the new folder I have created, also add as link is not an available option)
  • Create a “Filter” (what the other folders appear to be) within Visual Studio. This results in the layout I desire, but I have to add the source code files to the filter manually which just copies them to the .vcxproj file directory. I end up not modifying the actual files I added.

How can I add this folder and it’s files while keeping up with the original copies?