Adding additional includes breaks my class

So I wanted to include “GameFramework/CharacterMovementComponent.h” so I can store a reference to the component in the class as opposed to having to call GetCharacterMovement() a billion times. I added the include right underneath pragma once and defiantly above the .generated. However when I had that include in my .h file it throws a whole wake of errors.

My UCLASS() macro has: This declaration has no storage class or type specifier.

My class keyword has: Expected a ‘;’.

Almost all my virtual keywords have: Invalid specifier outside a class declaration.

My overrides have: Expected a ‘{’.

And one of my public keywords has: expected a declaration.

I also just realized even when I comment out the include I added my code is still broken with all the same errors. Could it be that if you put anything new up where the includes are it breaks?

I’ve been having this same issue since getting 4.8. I’m trying to include a new UObject class in my character class, and whenever I add the #include I get those same errors, and removing the include doesn’t fix it

Edit: This also happens when I try to define an Enum in any class file

Did you ever find a solution to this issue?

Hey -

After creating a new project and adding my own class to it, I added an include statement for “GameFramework/CharacterMovementComponent.h” and was able to compile successfully. Could you post the error list and output log from the failed build after adding the include statements? Additionally, could you include the code files that you’re using that are not compiling.

Cheers

Hey -

We’ve not heard from you in a few days and for tracking purposes I will be marking this post as resolved. If you are still having any issues related to the original post please feel free to comment here to reopen the post and we will continue investigating.

Cheers

EDIT (provided by Steam Shift):

If I put the new include above all other includes on an already existing blank like the error doesn’t happen. This is not a solution however. Only one additional include can be added this way. Adding a new blank line in any way will trigger the error.

I think I have the same issue.
I made a new class derived from Actor and if there are not EXACTLY 7 lines above UCLASS() it says “IntelliSense: this declaration has no storage class or type specifier”

Hey Ch4nKyy-

Does this include adding additional white space above the UCLASS macro? After creating a class based on actor and pressing Enter to add blank lines I was still able to compile successfully. If you are adding additional include statements you will still want the “.generated.h” file to be the last include listed. If other include statements are listed below this (between genereated.h and UCLASS) then this will cause compile issues.

Yes, even blank lines were a problem. No matter where. The project even compiled, but VS showed me hundreds of errors in my class, what made it impossible to work.
However, today the issue is gone.
To work around I forwarded the classes below GENERATED_BODY() instead of above UCLASS() and wrote some code and when I tried it today, it works.
Some weird interaction…

Hi! I got the same error.

It seems I could actually get rid of the errors by removing any blank lines between the includes and the UCLASS() Statement. :confused:

I am seeing this as well… It’s really annoying.

Taking a default actor, and adding only:

#include "Http.h"

results in the “This declaration has no storage class or type specifier.” error.

Hey edcolmar-

Are you adding this include in the .cpp or the .h file? If you are putting this in the .h, is it being added above or below the .generated.h include? If the include is being added below the .generated.h then this would be expected because Unreal Header Tool (UHT) looks for this include to be the last in the list.

I started using a specific workflow whenever I changed anything above the class definition in my .h or .cpp files:

  1. Before changing anything, make sure it compiles.
  2. Make the change.
  3. Save.
  4. Close VS
  5. Open the .uproject file
  6. Compile in the editor
  7. “Refresh visual studio project” in the editor
  8. “open VS” in the editor

I’m having the same error. I’m using VS2017. If you add a black line of even if you take away a blank line the error happens.

Edit: If I put the new include above all other includes on an already existing blank like the error doesn’t happen. This is not a solution however. Only one additional include can be added this way. Adding a new blank line in any way will trigger the error.

What’s even more annoying is that Unreal Engine staff marked this as resolved. Dude this is broken. Just fix it or if it has been fixed, make a statement like: blabla version has fixed this or whatever. For now only workaround seems to be @Steam Shift 's: only add include statements to already existing lines, dont mess with lines above UCLASS

Hey Steam Shift & muhsinfatih-

Can you provide reproduction steps of how you’re getting this to occur and the exact error messages you get when you try to compile? What include statement are you adding? Are you adding the new includes above or below the ****.generated.h line? When I open the VS solution for a project, I am able to create new code classes and add new lines / new includes and compile successfully. Please let me know how I can recreate the behavior you’re seeing.

on UE4 version 16.3 and VS 2017 when I open any header file with VS i get the same results as the OP: when added a new line or deleted one, random errors about UCLASS show up. I will try it with UE4 17 when I can. However my point is that the accepted answer being “we’ve not heard you etc etc” is not cool. If this were stackoverflow you would have gotten lots of negative points. Think about it this way: what should visitors see marked as answer when they come to the page?: The exact post that resolves the issue. if issue is resolved in comments instead, I urge you to update your answer to include the resolution, that way you would have a better documented forum with higher quality content.

What exactly do you mean by “when I open any header file”? Local testing has not been able to reproduce the reported behavior, so having a sample setup / repro case from those expericing the issue will help uncover the cause. For reference, here are the steps I tried:

  • Create new project
  • File->New C++ Class → Actor class
  • In MyActor.h, add #include "Engine.h" above #include "MyActor.generated.h"
  • Compile

Following this the project compiled successfully with no errors. If you are doing something differently, please let me know.

Are you running UE4 16.3 ? Is your VS version 2017? Did you try adding extra blank lines before UCLASS() ? header file you opened should be fine to reproduce. Though if you still can’t reproduce the error try it with a blueprint library class header file

Yes, I tested 4.16.3 and 4.17.1, both using VS2017. I tried adding additional empty lines and random include statements. I also tried adding a new Blueprint Function Library class with additional blank lines / include statements. If you’re seeing this behavior in a project locally, can you provide the setup used and/or the project itself? Also, what is the exact error message you’re seeing on compile?