IWYU vs Official Class Implementation documentation

Hi person who decided to click on this post,

How does this section (Class Implementation): Gameplay Classes | Unreal Engine Documentation
correlate to this:…WYU/index.html

Specifically, the Class Implementation section in the first link is documented to be at 4.22 (very recent) and states: Generally, you just include the header file for your game project, which will include the headers for the gameplay classes in your game project."

I interpret IWYU to include that which you “use” being the key word, meaining, explicit vs implicit. Including just the header file for your game project sounds like implicit usage.

So is including the header file for the game proeject, which includes the headers for the gameplay classes, following the IWYU protocol, or, is it violating the IWYU (I vote violate as I understand these two docs) I would think ONLY including the header files in my gameplay classes that I “use” in those classes is what follows the IWYU protocol.

Could you shed light?



Yes, IWYU boils down to including the bare minimum it takes to compile your code. Do you use UStaticMesh in your actual code? Include it in your CPP file (use a forward declaration if needed in a header file), otherwise don’t include it as you’re just making more work for the compiler than needed which will eventually be stripped by the linker - so you’re spinning your wheels for nothing.

It’s all about reducing overall compile time. Avoid Monolithic headers (e.g., EngineMinimal.h) and keep your includes lean as possible.

Hi @ExtraLifeMatt , Thank you for responding. The original post had the same destination in both links. I fixed it.

I was not clear because my question remains unanswered. I understand the thought behind IWYU.

My questions are:

  1. In the official Class Implementation documentation (the link in original post takes you to the short section) what is this statement referring to. *“Generally, you just include the header file for your game project, which will include the headers for the gameplay classes in your game project.” *Is it referring to custom gameplay .cpp files including [project].h, or custom gameplay .h files including [project].h ?
  2. Regardless of the answer to question 1, does that (just include the project.h) not sound contradictory to the whole IWYU? I feel this way because including a [project.h] in all gameplay classes (.cpp or .h) sounds just as wide open as including EngineMinimal.h. Am I missing something?


It is a bit contradictory, yes. You should only include what you actually use, but you have to include your Project.h - which normally has reference to the Engine.h or some sort of older monolithic header.

I imagine Epic is trying to clean that up, but the principle behind IWYU is still solid. Basically, try not to make code references / header includes worse. :slight_smile:

Thanks @ExtraLifeMatt :slight_smile: I appreciate the response and agree, it is likely cleanup is in progress (though, that Class Implementation document was versioned 4.22).