I would like to start out with I am still new to Unreal Engine. I know a bit but still have a lot to learn. I am not really sure if this should be a question or a discussion, so if it is in the wrong place I apologize.
I like a clean folder structure. For example I like all my classes pertaining to my character to be in a character folder. Inside that folder will have my private and public folder along with a folder for my animations. The structure would continue. I know this is a very light example, but the structure could get a bit deeper with the right system. So I guess my question is, are we not supposed to use this structure anymore? Feels like its a huge hassle to attempt if you like a structured folder layout. To include any header file, you have to list the entire folder structure leading up to the said file. Again with the right system could get lengthy. Am I doing something wrong? Should I set up the private public folder structure differently? Throwing all the files in the source folder is not an option. To me that is very unorganized and I don’t know, just doesn’t feel right.
It definitely possible, you just have it slightly backwards for what Unreal wants.
Here’s an example from one of my plugins:
Everything in Public is stuff that is meant to be included by other modules/projects/plugins/etc, so headers basically.
Everything in Private is meant only for this module, so mostly cpp’s but also headers not for public consumption.
From there you can add whatever organization you want. When you include a file, you would at the directory after Public. So if the file’s directly in Public it’s just
#include "foo.h" but if you add any structure you would do something like
It’s true that they can get long but that’s where you have to decide your own balance between organization and the implications on source code. But most IDE’s have some sort of “Add Include” tool that allows you to just write code and then do the includes later and not really worry about it too much.
That’s the setup I went with. I looked a bit more into it and seen that ideally that’s how it should be done. I know when I looked into the directory structure on the docs, that’s how it was laid out, but all the plugins and editor layouts had it the way I mentioned. Either way I do it, my engine makes me do #include “StrategyTech/Public/UI/Foo.h”? Again maybe I did something wrong? Yes my IDE has an “Add Include”. Honestly includes it by itself. The only time I have to change it is when I first create the class. My only issue is if it becomes something like
#include “ProjectName/Public/SubFolder/SubFolder/SubFolder/foo.h”, may look a bit odd and not right? I could be wrong though. I could just be over thinking things.
You may be missing some setting in the Build.cs file for your module. I’ve definitely had to add to the PrivateIncludePaths there, but only for a Private subdirectory. I’ve never added one for a Public directory.
The editor plugins are a little weird because they add a bunch of extra optional layers on top of the Source directory. Under /Plugins you can have whatever structure you want. Eventually you’ll have a /Source directory which contains Module directories which should have Public and Private underneath along with a build.cs. From there you can do whatever you want again. And you should be able to include from the part of the path that comes after Public or Private no problem.
Do you have any difference between your own files and includes from other modules that you’ve included in the PublicDependencyModuleNames or PrivateDependencyModuleNames?
Perfect! Adding the PrivateIncludePaths in the Build.cs did it for me. I knew it had something to do with not having the right pointer to the folder structure, just didn’t know how to go about it. A quick google to the method gave me all the answers I needed. Thank you a lot for your fast responses! I’ve been looking up a lot of things and seems a lot of people don’t really use this folder structure. I personally like it. Its clean and organized. Another thing people don’t follow is the naming structure i.e. SM_, SK_, BP_, M_, MI_, and so on. I like organization and try to keep things structured. Again thank you.
Possibly there is a setting in the Build.cs file for your module that you are missing. It looks like I’ve definitely had to add to the PrivateIncludePaths there, but only for a subdirectory under the Private folder. I have never added a Public directory to my list of directories.
I find the editor plugins a little strange because they add a bunch of additional optional layers to the top of the Source directory, which makes things a bit confusing. If you want to organize the plugins under /Plugins in any way you want, then you can do so. As a result, you are eventually going to have a directory called /Source which contains directory named Module which is going to have Public and Private underneath along with build.cs. From thereIt should be possible for you to include files from the part of the path that comes after Public or Private without any problems.s after Public or Private no problem.
I was wondering if there was any difference between your own files and those from other modules that you have included in the PublicDependencyModuleNames or PrivateDependencyModuleNames?