has anyone noticed a problem with the default include paths when creating a new C++ project in unreal??
for example, I go to Tools > New C++ Class in the Unreal Editor and create a new Character class in the “Player” directory. so my files will be created in:
the generated MyCharacter.cpp has the include: include “Player/MyCharacter.h”
but the project won’t build because it can’t find the header file. i can get it to build by changing the include to “MyCharacter.h” because the cpp and .h are both in the Player directory.
i went to project properties in Visual Studio (Project Properties > VC++ Directories > Include Directories) and manually added:
$(SolutionDir)Source\MyGame
this seems to work for now but i never had to manually adjust the include paths in a generated project like this before. does anyone know if this is a bug with the project generation in Unreal?
Visual Studio properties won’t work 100% because those are temporary files. They could be deleted or regenerated from scratch by Unreal tools. I’m even surprised that they have any effect on the build process at all quite frankly.
The two expected solutions are:
Introduce Private & Public directories so that all your source goes into Source/MyGame/Public/… or Source/MyGame/Private/ … (cpp always to private, headers mostly to public but it can depend on the header). By default, this directory is added by the unreal build process so an include of Player/Something.h in MyGame/Public will be found by any code in that module (or code in other modules that depend on MyGame.
In the MyGame.build.cs, you can add to the PrivateIncludePaths “MyGame”. This will also allow an include of Player/Something.h to be found my includes in the MyGame module.
Option 1 is what I do everywhere and what should be done for modules in plugins. Option 2 doesn’t work well with plugins because you’d have to add to both the PrivateIncludePaths as well as the PublicDependencyModuleNames/PrivateDependencyModuleNames which would be very annoying. Adding to the ModuleNames arrays adds the Public directory as an include directory for the module.
So you can do Option 2, but it only really works for the Primary game module. And even though only if your project only has the one module.
It’s possible it’s an issue with specific templates. You don’t say how you created your project in the first place. I’ve never let Unreal create those files for me.