Structs cannot be declared in their own file(s)

#The bug

  • Create a blank file (I used /Game/Public/Structs/MyStruct.h)

  • Add the following code

    #pragma once
    include “Object.h”
    struct FMyStruct

  • Compile

You will get the following error: error C2143: syntax error: missing ';' before '}'


After much debugging, I have finally found the issue using the Struct reference, in the line that states

Structs are declared prior to the class declaration.

Moving the same empty struct in front of a UCLASS declaration (empty or not) then allows the project to compile.


This is (arguably) a bug. At the very least, the error message should be more sensible/informative.

Actual solution found:

#include “MyStruct.generated.h”