Can inline files (.inl) be included from a UE4 header file?

I’m trying to include an inline definition file (.inl), which of course needs to be included in the header after the class declaration. However UHT of course throws an error because its .generated header wasn’t included last.

error : #include found after .generated.h file - the .generated.h file should always be the last #include in a header

Is there any way to coerce UHT into letting this additional include go? (This error seems to be the result of a superfluous check which although helpful is not strictly required).

  • Maybe there’s a UHT-equivelent of #pragma ignore?

  • Is it maybe possible to turn off this specific warning globally in UHT?

I realise that “tactically” I could simply put the inline definitions back into the header file, however this is a standard practice of working in C++; I’d really expect should be supported out-of-the-box. The reason why I’m doing it is that this specific file has a beefy set of inline method definitions, which really need to be broken out.

#pragma once
#include "ActorClass.generated.h"      // <-- Generated file needs to be last for UHT

UCLASS()
class CHESS_API AActorClass : public AActor
{
	GENERATED_BODY()

	// ... declaration ...
};

#include "ActorClass.inl"     // <- Inline definition file needs to be included *after* the declaration for the compiler

If you find yourself in the same position as me then here’s the answer. Surround the inline in an #if CPP preprocessor directive:

#if CPP
#include "MyFile.inl"
#endif

This way, it’s ignored by UHT, but picked up by the compiler.

1 Like