Thursday, May 26, 2016

Unreal 4 - this declaration has no storage class or type specifier (Fixing Failed Compiles)

The Unreal Header Tool (UHT)


The first thing to note about Unreal Engine 4 (UE4) is that the engine generates some headers for you. This is true for any classes, enums, and structs that has a UCLASS, UENUM, USTRUCT macro defined above them.  These 'decorators' automatically wrap your class, struct, enum with special reflection meta information that gives the Editor and game engine information about the object or interface that allows a designer to use or subclass a C++ code implementation in blueprint.

If your project won't compile or you're getting strange errors, the first thing to check is the Visual Studio output log.  The UnrealHeaderTool can fail, which will result in either no errors or warnings, or will result in missing *.generated.h  headers.  This isn't immediately obvious.  To check for this you need to open the output pane, by going to view - output or by pressing ctrl + alt + O.

One of the most common signs the Unreal Header Tool has failed is this message next to a GENERATED_BODY() macro statement indicating:

this declaration has no storage class or type specifier 



If the output pane contains any error you must correct these to get your compile working again!

In the image below you'll see I've highlighted the first error, this error resulted in erroneous editor errors so it's important to check the output pane first!



Generated Headers

When the engine encounters GENERATED_BODY() macro statements it responds by generating a header which is meant to be included in the source file.  For each source file with unreal engines reflection macro statements in them, there should be a corresponding generated file following the name:
FileName.generated.h.  To work this include must be the last include in the source file.

If you have a missing generated header, or the solutions above did not correct your problem you should try re-generating all project files.  This can be done by navigating to the main directory of your project.  (In Documents/Unreal Projects/NameOfProject).
Click right on your .uproject file then click "Generate Visual Studio project files"



Incomplete Compiles and Intellisense

Intellisense uses information created during the code analysis and build stages to know if code is formed correctly.  An incomplete compilation or even a breakpoint being set that prevents a program from fully running will generate erroneous Intellisense errors.

Before you correct any errors in your project make sure you follow the steps above, and disable breakpoints while ensuring you have allowed a full compilation to take place.

No comments:

Post a Comment