I have a UE4 project , And there is about 10 .cpp and .h files in another directory. I just want to add that directory as an Include path.
We can have script files in Source folder ,but let’s say I have a folder with 10 .cpp and header files in D:\MyScripts and my unreal project is in D:\MyProj , I want to unreal to search for source files within that D:\Myscripts folder. when I compile the project, There should be a way to specify include paths.
Is this possible ? if possible how can i do ?
I searched internet nearly for two days, but I couldn’t find anything helpful.
Hop someone can help me on this
There are no wildcards in C++ includes.
So far as I know the idiomatic way to accomplish this goal is to make another C++(header) file that includes each of the headers individually.
You may then include that file to include the whole folder.
INCLUDING DIRECTORIES IN SOLUTION WITH LINK
Example of usage of MKLINK:
C:\Users\Calem\Documents\Unreal Projects\UE4-MeleeTemplate\Source\MeleeGame>mklink /D Scripts "C:\Users\Calem\Documents\Unreal Projects\SG\Source\SG\Actors"
symbolic link created for Scripts <<===>> C:\Users\Calem\Documents\Unreal Projects\SG\Source\SG\Actors
Now there is a “Scripts” directory link in my MeleeGame.
If I generate visual studio files and open the solution, the Scripts directory will be included and will be a link to the Actors folder under my SG project.
I made this link in the top directory of my source, where you can also find my .h file, but you could put it anywhere else in the project that you like and it will still work fine.
It’s not about C++ wildcards , I want to specifiy a include directory in a seperate place than source folder. The question is how to link anotehr include directory ? how to have another inclulde path where unreal will search for .cpp / .h files ?
Ah, I may be confused! What is the separate place?
We can have script files in Source folder ,but let’s say I have a folder with 10 .cpp files in D:\MyScripts and my unreal project is in D:\MyProj , I want to link unreal to search for source files within that D:\Myscripts folder. There should be a way to specify include paths. , That’s what I am asking.
I see. There are a few ways to do this. My preferred way is to circumvent Visual Studio and make a symbolic link to the desired directory. You can make this symbolic link anywhere inside your UE4 project using the command mklink. Then regenerate your visual studio solution. The files will be included in your project. This way works well for me for Unreal Projects because everything is represented by the source directory without extra config files such that solution generation doesn’t become more complicated. Does that make sense?
I’ve edited my answer to include a solution with an example.
cool , i’ll check that ,If it helps i’ll mark it as answer and leave you an upvote
this is a ntfs junction , right ?
Actually it’s linking two directories, Not adding another path to Include path list of unreal project, So this is not what I want. I think I clearly explained my requirement.
Because of the way Unreal makes a solution based on a directory this is a good way to accomplish the goals, but if someone has a better solution I would also be interested in seeing it
What would a directory link do for you that a symbolic link would not in your requirements?
Adding include path is only useful if you do not want to use full path to header files like:
#include “/PathTo/File.h”
To add include path:
- Open Visual Studio
- Right click on your project in solution explorer
- Click Properties
- Select VC++ Directories
- Add required directory into Include Directories
NB: Include directories (paths) are used to search for header (.h) files only! So it’s valid for header-only or precompiled libraries (in case of precompiled library, you also should add it into Library Directories).
If you want .cpp files your directory contains to be compiled, you should also add them into your project.
I’d recommend you to do it this way:
- Right click on your source folder in Solution Explorer (or some other folder you want it to be in).
- Select Add → New Filter and type desired filter name (I usually use same filter name as folder’s name).
- Right click on newly created filter and select Add - > Existing Item.
- Select files (.cpp and .h) from anywhere you want. It’s better to add .h files for they were parsed by IntelliSense and it will be easer to access them for reading / modifying.
ADDON: I have missed one thing. In case of Unreal Engine, files being compiled by so called Unreal Build Tool but not with native VS tools. As far as I know, Unreal Engine compiles every C++ file it finds under Source folder of your project.
Let’s assume we have D:\dev\MyProject\Source folder with you project’s sources and D:\dev\3rdPartyGUI\Source folder with some third party library’s sources.
By making a link like so:
D:\dev\MyProject\Source>mklink /D GUI D:\dev\3rdPartyGUI\Source
you will make 3rdPartyGUI’s sources being compiled each time you compile your project.
Then, by adding D:\dev\MyProject\Source\GUI\ into C++ Include Directories in VS, you will make it’s header files accessible by simle #include “3rdPartyGUI.h” from anywhere in your code. You can also use it by adding path, like so: #include “GUI/3rdPartyGUI.h”, so this step is not required.
And last but not least - add 3rdPartyGUI files into your project. Make a filter called GUI, right click on it and add files from D:\dev\MyProject\Source\GUI\ for they have been searched by IntelliSense and shown in Solution Explorer.
Just refreshed VS project from editor and all my filters and additional items has been kept.
Not sure If I got you right about solution regeneration.
Why should you need to regen solution?
Will this be maintained after a regen of the Visual Studio solution? If they will that would be fantastic
Tested on my machine too and it works well. Regen solution sometimes necessary because of little issues, but mostly if the code is in revision control you don’t share the sln, eh?
I do share solutions, but never had problems with it. Probably because these solutions wasn’t created by UE.
Well, to be honest, I’m quite a noob in UE, so haven’t got at first, what problem with solution sharing could be in. Now I got you. Looks like solutions, created in UE are heavily dependent of computer’s environment.
Usually Visual Studio Solutions do not have such problems.
Well, in this case, if you have to rebuild solution file after each checkout, why wouldn’t you make some workaround for not doing this? There is a lot of ways to do it. For instance, you can simply keep your own version of this file all the time.
For instance, I’m using dropbox to share some UE projects between my computers. So what’s the sense to share whole project’s folder? I’m currently sharing only Config, Intermediate/Config, Contents and Source folders.
BTW, solution file is just a list of project files and a list of build options.
Actual configuration being kept in project files, which are dependent of your engine’s path. If you are gettin’ troubles with your community’s vcxproj files, you can simply check, what path to the engine being used there and make an appropriate link to your engine’s folder. Fastest way to do it - just open your Project/Intermediate/ProjectFiles/UE4.vcxproj with Notepad. Find something like:
<ItemGroup>
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Source\UE4Editor.Target.cs" />
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Source\UE4Game.Target.cs" />
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Config\Base.ini" />
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Config\BaseCompat.ini" />
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Config\BaseDeviceProfiles.ini" />
<None Include="C:\Program Files (x86)\Epic Games\4.12\Engine\Config\BaseEditor.ini" />
So you can see, where original author’s UE folder is. Then go in your shell into C:\Program Files (x86)\ (in this case) and make there a symbolic link to the location of your engine like:
mklink /D “Epic Games” “X:\My\Path\To\Epic Games”
It depends heavily on the revision control you’re using. Sometimes you don’t, sometimes you do =)
When sharing my projects over git or perforce, I typically don’t share the intermediate or config, but perhaps I should in the future, or at least some subset of it.