Gamename.h doesn't get included

Hello, in my gamename.h file I have some code that should be accessible everywhere in order to avoid including the same file in all the files.

The code I have in there is my own header for logging, some non-default collision profiles and ECollisionChannels for non-default object/trace collision profiles, so I don’t have to memorize which one is for enemies, projectiles etc.

I started using this header file a few days ago, and it just “worked”, the project compiled successfully, but Rider always said that the stuff from there that I’m using is not declared/defined, so the code is illegal. Sadly, now they’re also build error.

Does anyone know how to fix it?

There are no files that are automatically included for you. If you’re not including it, none of it’s contents will be available. You fix it by properly including the headers that you are dependent on.

Previously you may have been running into the “Unity Build” process which compiles cpp files by combining them together into a bigger cpp file before compiling it. When this happens it can mask include problems because include from other cpp files will be “available” to cpp files that forgot to include it.

You may have reached a point where your code is built as at least 2 unity files, and one of those doesn’t have/start with a cpp file including your Gamename.h.

2 Likes

Thanks for a detailed reply.

Can you tell how I can include that file everywhere by default, please?

I don’t believe there is. At least not with the way that Unreal has setup their build system.

An auto-include like this is fundamentally at odds with the Include What You Use (IWYU) methodology of good C++. You really don’t want a file that when edited causes every source file in your project to have to rebuild. You want it to only rebuild the files that are directly dependent on it. Unreal has been transitioning away from encouraging these sorts of monolithic headers.

Usually this results in smaller, more well defined headers instead of a single god-header like what you’re describing. Like common logging in one header and collision profiles in another.

1 Like

Hey @JekiTheMonkey,
It’s one of the ways Unreal preserves performance, and a certain property of C++ as @MagForceSeven explained. It also helps in debugging, because splitting all of these things up means that you have a very specific file where the issue lies.
Unless you want to start delving into overriding classes, there might be a way to delve into the Pawn or Actor class to add some functionality, but, this may come at a great risk to performance.
I hope this can help!
-Zen

Thank you both for replying.

Recently I was investigating ActionRPG C++ code, and saw that their ActionRPG.h includes a bunch of headers and declares a log category, but after double checking it today I noticed that they manually include that file in every header. I should’ve pay more attention to their includes beforehand. :sweat_smile:

Nevertheless thanks for explaining some actual C++ practices.

1 Like

@JekiTheMonkey,
No worries! I feel as though my own debugging is just going through things until I remember what I forgot! :sweat_smile:
Good luck with your developing!
-Zen

1 Like