[SOLVED]Including header files in my GameMode invalidates entire class

So, I’ve got one I’m stuck on. I’m attempting to wire up my GameMode, PlayerController, and Pawn in C++. This is more an exercise in using C++ vs. Blueprints, but I’ve run into an odd issue. If I include the header files from the PlayerController and Pawn in the GameMode, the Unreal Macros invalidate and it cause the class to invalidate. I’m not exactly sure why this is. I’ve attached a screenshot showing the issue.

EDIT 1: I’ve used forward declarations to solve this issue, and moved the includes into the RPGGameMode.cpp file, but I’m still interested in knowing why including them in the header file does this.

Do you have the includes on all the class headers? If you include your pawn in gamemode.h and gamemode in pawn.h it will produce an error with circular dependency. You probably knew this already.

Other thing that seems to be amiss, is that you did an #include after the generated include. All includes for ue4 need to be put before the generated include. The Unreal Header Tool demands this, if I’m not mistaken.

Neither the pawn nor the controller include the game mode. I’ve also tried moving the includes above the generated includes, with the same outcome.

Hmmm, got me at a loss here then.

I can’t see the error messages clearly from the pictures, but atleast one thing there is that might cause the error: You have defined variables in your header. I’m not sure if this would actually produce those specific errors, but they might as you are including your public defined variables for all the classes. They might clash with your other classes. I can’t see the actual error message from the screenshot, so it’s hardish to determine. Try declaring them in the header and defining them in your .cpp constructor and see if the includes work.

It’s happening no matter where I place the declaration. I started a new project to see if it was project specific, and it’s happening there too. Once I add an include, the UCLASS has an error stating “This declaration has no storage class or type specifier” and it kills the class definition.

It’s happening no matter where I place the declaration. I started a new project to see if it was project specific, and it’s happening there too. Once I add an include, the UCLASS has an error stating “This declaration has no storage class or type specifier” and it kills the class definition.

That error code indicates that you are indeed running some code in your header, ie. putting expressions where declarations should only exist.

Try removing the casting from your header. So the lines where you declare and define Controller and Player -variables - these lines of code go inside a function with the GetWorld, which is something you can’t do in a header (to my knowledge).

If you did this already, and you get this same error message with a completely empty header with only includes, then I’m at a loss.