What dependencies should I add in my Build.cs?

Hi,
quick question. I just created a new project with simple UMG UI – child class of UUserWidget (with meta=(BindWidget)) and Widget blueprint, but I forgot to add the “UMG” dependency to Build.cs file. But it all compiled and worked just fine anyway… Why is that?

My guess is probably because I have “Engine” in public dependencies and it has “UMG” in it’s private dependencies? (and also CircularlyReferencedDependentModules – I have no idea what that is)

If it’s the case, why does every documentation instruct us to add the dependency ourself if it’s included anyway? Just a good practice, in case you would remove the Engine dependency or something? But if that’s the case, shouldn’t we explicitly add everything else Engine.Build.cs adds if we use it?

Also should Slate and SlateCore be explicitly included when UMG is used as UMG is built on top of Slate? Some guides (like the official one) do add it but most don’t. “UMG” depends on “Slate” and “Slate” depends on “SlateCore”, so technically only “UMG” dependency is needed. But if you add it as good practice, why don’t you also add “Json”, for example, as it’s also “Slate”'s dependency…?

None of this probably really matters, but I’m really new to Unreal Engine, and I’m just curios for educational perposes :slight_smile:
I feel like a reasonable option would be to explicitly include everything I do use directly in my code – so if I do directly use any class from “UMG”, I should add it. But that does not go along with the official documentation, where they add “Slate” and “SlateCore” even though they use classes just from UMG…

What’s your opinion? What do you explicitly include in your projects?

As I understand it, you need to add dependencies only when you want to access some internal functions/variables of some things. Like Slate, for instance. You can use widgets a million times and they all use slates, but not include Slate in the dependencies. But once you want to explicitly modify a slate in your code, you must have that dependency added.

Even if your project compiles just fine, a missing module or missing header include is a bad thing. It might cause your project to fail compiling later on. Right now you had the luck that a dependency was included elsewhere.

I always google my datatypes like “ue4 UWidget”, then the first result will be a class hierarchy page of the UE docs:

Showing the header and module required.
I also include every single type’s header following these instructions:

The header includes are made in the .cpp files instead of the .h files whenever possible (whenever I can get away with a forward declaration in the header) to improve performance.

1 Like