GENERATED_BODY macro causes error "this declaration has no storage class or type specifier"

Hey guys,

I’m fairly new to UE and am currently busy (or at least trying to) with the 3rd Person Power-Up Game with C++ video tutorial. Already in the third assignment, after creating my first class, I’m running into problems. First, I know that the tutorial has been made using ver. 4.2, but I downloaded the 4.7 source code to accomodate for that. But now, Visual Studio/Intellisense is underlining the GENERATED_BODY macro in red, telling me that “this declaration has no storage class or type specifier”. I didn’t even edit the file! Of course, the public: access specifier is also underlined because the line before is erroneous and now it “expected a ‘;’”.

I’m so confused and also quite sure that it is some really simple thing that I just missed… :expressionless:

Please, help me?
Thanks

Does nobody have any idea? Not even the slightest?

Have you tried compiling? Basically you have to ignore intellisense errors, as these do not affect the actual compilation.

4 Likes

No, I actually haven’t tried that. :smiley: I just thought that VS wouldn’t do anything, if it encounters any errors.
Edit: When I’m back home, I’m gonna try it immediately.

Are you home yet? I’m having that error too.

5 Likes

Kinda old thread but I’ll just ask, did you have an include after your “generated.h”? Cheers.

5 Likes

Go to the root pro path,
regenerate visual studio project files again.
Warning will disappear

2 Likes

Same issue experienced on VS 2017 15.9.9. In your ‘Solution Explorer’ in the top right of VS, right click on on your main project (under the folder Games). From the context menu that comes up select ‘ReScan Solution’. This solved the problem for me on this occasion. Intellisense seems a bit flakey at times and sometimes I’ve found the best solution is to just come out of the Unreal Engine and VS and just go back in again.

If anyone still wondering, the unreal macros require that the code that follow don’t skip a line. So if you add a empty line after this macro (Probably before the “public:” keyword) the intelisense will pick it up and show a internal error (In the atomic file in my case). If this works for any of you let me know

11 Likes

Thanks for your suggestion, but that didn’t help me.

1 Like

The fix for me was actually to* add *an extra line after GENERATED_BODY(). Thus, there are two line skips before the next contents (“public:”). Here is the working code:


UCLASS()
class UOculusIAPBPLibrary : public UBlueprintFunctionLibrary
{    
    GENERATED_BODY()
     //Line skip 1
     //Line skip 2
public:

Coincidentally, it seems to need an extra line for each new UFUNCTION added, which is weird as there were already multiple…I’m thinking maybe it doesn’t like comments on the lines before each UFUNCTION.

Apparently, it’s also not good to have multiple UClass() calls in the same constructor file. If there are multiple classes, call them individually without adding the “UCLASS()”, nor “GENERATED_BODY()”

4 Likes

I found the next solution (thanks r/unrealengine for this): GENERATED_BODY() macros must stay on the same line of code. idk how it works, because yesterday I added new #innclude and everything was fine but today I got error from adding new line before it and moving macros from 13 to 14 line. TO fix it all I had to do is make it stay on the same line by deleting comment on the first line. And don’t forget that #include “GameFramework/Character.h” must be your last include in the list, I find out this could also cause the error.

1 Like

I just found this old thread of mine and am amazed that it’s still (kind of) active. In the meanwhile I also found out another cause for this “error”—and btw., all your answers made it clear to me that it all is basically just about code style: So, Intellisense also complains about the GENERATED_BODY() when you put your opening curly braces at the end of the line of the class declaration, instead of the next line.

So, this code (style) is not allowed, according to Intellisense:


UCLASS(config=Game)
class ATestProjectCharacter : public ACharacter {
    GENERATED_BODY()
    ...

Back in the day, “opening curly braces at the end of the same line” has been my preferred code style and consequently, I set up my VS to autoformat everything that way.

And to answer your concerned question: Yes, I got home that day (I assume). But I can’t tell you whether or not I tried to compile the project. I have only been working with UE4 again for the past year or so and got used to UE4’s own code style, so I haven’t really run into this problem again.

3 Likes

Hey sorry I know this is an old thread just wanted to mention for anyone else that stumbles across here.

A lot of the time when you get the error on GENERATED_BODY() in the .h file, and BeginPlay(), TickComponent() in the .cpp, but Unreal Engine still compiles fine, you just need to refresh the project. To fix and get rid of the errors, save all your files and anything open in Unreal, close it all down. Now go to that projects folder on your PC, and delete the Binaries folder. Once that’s done you can reopen the project and unreal will recreate the Binaries for you. In the Unreal Engine now, click file>Refresh Visual Studio. Now when you open your code again the errors should be gone.

Hope this helps someone!

15 Likes

I Can Allready ,Answer from these Site:

Please, Check then Question or Comment

All you need to do fix that is after creating VS project, open the Unreal Editor and click Tools > Refresh Visual Studio Project

3 Likes

I just found out that if you remove include “GameFramework/Actor.h” then the error goes away. I don’t know if this is the right approach!

Thanks!!! It worked!!!

Can confirm that this worked in version 5.1
Thanks a lot!!

All you need to do fix that is after creating VS project, open the Unreal Editor and click Tools > Refresh Visual Studio Project

This is old but for reference, this error can be caused by multiple reasons, it is a macro and the code should be ok in order to the generated code be ok, in my case, i have an unimplemeted function in a .h file, so til i have implemented the function the GENERATED_BODY line appears with an error