Engine/Source/Runtime/Engine/Classes/Components/SphereComponent.h
#include “Components/SphereComponent.h”
Why is the code shorter?
Engine/Source/Runtime/Engine/Classes/Components/SphereComponent.h
#include “Components/SphereComponent.h”
Why is the code shorter?
Hi,
when we create a C++ project under unreal engine, there’s a C# (.cs) file that contains the paths for our includes.
This file is named .Build.cs.
By default this file will have this line :
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
And as you can see in the modules names, there is a module named Engine and that module is the module you find in your long path include :
/Engine/Classes/Components/SphereComponent.h
To experience that, try and delete the Engine from the include in your .Build.cs, and try to recompile your project, normally you should receive this error :
Cannot open include file: 'Components/SphereComponent.h': No such file or directory
For me, the proper way to include a file in c++ under unreal engine is to get all his path starting from Runtime, in the case of SphereComponent, I would prefer doing this to avoid any potential includes problems :
#include "/Runtime/Engine/Classes/Components/SphereComponent.h"
Hope this explains to you why the code is shorter
Hello! It is connected to search headers algorithm of compiler. The thing is that in your build.cs file you add some modules - all stuff that is added there is used when generating proj files. And so, in your proj files there will be module paths and folders paths, that will be used while searching for headers.
Thank you
But I wrote “Engine” in build.cs but not “Classes”
Where did Classes come from?
Import paths should always start after the Classes or Public folder. So you should be using “Components/SphereComponent.h” and not the full path starting from “/Runtime”.
For more details on modules and header import paths you can check out this UE4 Modules presentation: UE4 Modules - YouTube
@koutaaiba, In the build.cs we only include the name of the module itself not the specific folder. For example if you go to Unreal Engine’s source files, under UnrealEngine/Engine/Source/Runtime/ you will find all the internal modules used by Unreal Engine (by Internal I mean not other Plugins). There you can find the module Core, CoreUObject, InputCore and Engine, those are the modules included by default in your build.cs. Under Engine you will find three folders, Classes, Public and Private and there you will find all the classes declarations, headers (.h) and source files (.cpp).
As said by @Kahel18 in the comment above, the compiler’s search header algorithm gonna search for the wanted file in those folders.
@Flassari both methods are correct if you don’t forget to include your module in the .build.cs, as I said the full path is the proper way for me because for example I always want to see from which module my file is included. Both ways are correct
thank you!!
This is also a very good article that I really enjoy reading. Not every day I can see something like this. Hope you will have more good articles to share with us. If you have more time, please visit:
mapquest directions