UnrealHeaderTool assertion failed: CodeGenerator.cpp Line 2049

I’m trying to build my game project after restructuring a number of source files. I’ve deleted the .vs, Binaries, DerivedDataCache, Intermediate, and Saved directories and regenerated the Visual Studio Project files; but I keep running into an error from the UnrealHeaderTool - and I’m completely lost as to where to even look for the problem.

I get a Critical error, Assertion failed - and it points me to line 2049 of Engine\Source\Programs\UnrealHeaderTool\Private\CodeGenerator.cpp

And there I find this:

for (auto* RawUClass : SourceFile.GetDefinedClasses())
{
    PrologMacroCalls.Reset();
    InClassMacroCalls.Reset();
    InClassNoPureDeclsMacroCalls.Reset();
    StandardUObjectConstructorsMacroCall.Reset();
    EnhancedUObjectConstructorsMacroCall.Reset();

    auto* Class = (FClass*)RawUClass;
    if (Class->ClassFlags & CLASS_Intrinsic)
    {
        continue;
    }

    auto* ClassData = GScriptHelper.FindClassData(Class);
    check(ClassData);  //<-- this is line 2049

    // C++ -> VM stubs (native function execs)
    ExportNativeFunctions(SourceFile, Class, ClassData);

    // VM -> C++ proxies (events and delegates).
    TArray<UFunction*> CallbackFunctions = ExportCallbackFunctions(SourceFile, Class, ClassData);

...

}

So it’s cycling through (all?/many?/some?) of my classes and at some point throws the error during the check.
Is there an UnrealHeaderTool log anywhere so I can at least see which class is causing the assertion failure?

At this point I’m transferring the modifications made in the new project to a cloned backup file by file and line by line until the problem reoccurs. Is there a better way to track this down?

Hey -

Can you identify how you “restructured” the source files? Changing the source files could affect how those files are by other source files. Without knowing what changes were made it will be difficult to point to where this error is generated from.

I found the error (missing semi-colon after forward declaration), but what I’m more interested at this point is how to avoid the laborious line-by-line search in the future.

Does/can the UHT output any kind of log?

In my experience with UE4 (really all programming), the worst/most time consuming errors are trivially easy to fix once found (e.g. include semi-colon), but it can take literally days to find them. The biggest headaches and worst time-wasters are when one gets an exceedingly generic error without any indication of even the file that was being parsed.

In this case I got a reference to the line where the check failed, but that line encompassed a check running through the entirety of my code.

Just had this one happen to me. My cause was some accidental text written into a header file (not inside any class definition). Would have thought it would be caught by the compiler…

Same Critical error, Assertion failed line 2049 of Engine\Source\Programs\UnrealHeaderTool\Private\CodeGenerator.cpp

I just encountered this as well, but my problem was line 2003. Missing semicolon after a forward declare. Glad I found this post!

thanks, @ for feedback which you found your error line. i had get the same error and lost a lot of time to found exact error line that causes the CodeGenerator.cpp error. then, I have checked all forward declaration lines of all header files. finally, I found a quotes symbol that I have added by mistake.

hint for all of ue4 c++ developers; if you are writing code out of class declaration, you should extra care your finger :slight_smile: