You should use the PublicDependencyModuleNames list if you use the classes from a module publicly, such as in a public .h file. This will make it possible for other modules that depend on your module to include your header files without issues.
You should put a module’s name in the PrivateDependencyModuleNames list if they are only used privately, such as in .cpp files. Private dependencies are preferred wherever possible, as they can reduce your project’s compile times.
I don’t understand this on the first paragraph: …if you use the classes from a module publicly… What does it mean?
Normally, when I use a class as a parameter I use forward declaration. If I use forward declaration, do I need to add the module dependency as public?
Sorry, but I don’t understand what “use the classes from a module publicly” means.
Unreal source is segmented into modules, even your game project is considered a module, a plugin for example is also its own module.
When you need to access a certain module you need to add it as a dependency, by default your project already has access to a few modules by default but there are special cases where you will need to add the module as a dependency.
I’ll give you an example, I need to check if the application is in the background or active so I can use the following code and I have the header file include
When I try to compile I get a linking error, usually a linking error indicates you’re not including a certain header file or you don’t have access to a module that you’re accessing.
In this case to solve the issue I need to go to my Build.cs file and add Slate as a dependency so I can access its headers. I don’t need SlateCore for my case but I added it just in case I might need it.
If you need to know what module name you need you can inspect the header file path and in this case it’s Slate, however sometimes the name is different so you’ll have to google it.
The difference between public and private dependencies affects how the module’s includes and symbols are exposed to other modules.
Most of the time adding as a public dependency is all you need because what you need (the dependency aka function, struct etc) is in the header file.
Sometimes a module can define certain symbols inside a C++ file in that case you will need to add that module as a private dependency as well to be able to access the dependency.
To answer your question, the way to know is to see where that decency is located, if it’s in a C++ file then you need a private dependency if it’s a header file then a public one. Sometimes starting with a public and hitting the compile button might help you decide.