UCLASS() throws weird errors. Can't #include

Hey everyone,

I am having a major issue with UCLASS macro and the “something.generated.h” files.
I’ve read around 10 posts (couldn’t find more) with people who have the same issue but neither post helped me with my problem.

The issue is: UCLASS() throws weird errors when adding anything above itself.

I am not:

  1. Including anything between the “something.generated.h” files and the UCLASS macro.

  2. Messing with anything inside the code other than adding whitespaces or #include at the top.

I’ll be trying to explain this through images, so you can clearly see the code.

Here I have no errors, I have some weird spacing at the top as you can see (no spaces between Copyright, pragma once, first #include) because that would put UCLASS outside of the 10th line, and give an error.

Here it is:

The only change I have made in the entire code is adding a line between #pragma once and #include "CoreMinimal.h"
If I make a build here, it succeeds. But it makes me unable to code anything else because almost every line in the .cpp file has an error mark now, saying UGrabber is not a class. Because of that the IntelliSense isn’t helping me anymore.

It seems like the UCLASS macro picks itself a line to be on. In this example, it is the 10th line. Putting it anywhere except the 10th line resolves in an error.

A couple projects ago, this was the 11th line. Putting it anywhere else gave me the exact same error.

I’ve tried:

  1. Changing the solution configurations between Development and Development Editor (suggested in another post).

  2. Building, Rebuilding, Cleaning and Building, Restarting, Refreshing the VS Project from UE Editor

And that was it. Not many suggestions have come up. I need urgent help on this.

EDIT: The UCLASS error which let me compile before doesn’t let me compile now and gives these errors.

The red error marks were always there, but in the 2nd picture I could compile. Now I can’t. This just seems to be random.

Hi,

Are you actually experiencing compile errors, or are we just talking about the red squiggles from IntelliSense?

Steve

I have had issues with compilation before, but I can’t replicate it now. Error was, “name followed by “::” must be a class or namespace name.”
It gave this error because it doesn’t qualify my UGrabber class as a class because of the errors.
And even if the compilation succeeds, the red squiggles from IntelliSense become a huge issue if you have them all over the screen ( .cpp file for instance). Because of that, any changes I do, IntelliSense thinks there is an error and not help me with anything.

EDIT: Managed to replicate the error. I will edit the post accordingly.

You will need to compile in order to update the .generated.h, which will contain references to the UCLASS, GENERATED_BODY etc. line numbers in your header. Once UnrealHeaderTool runs, it should produce a new .generated.h with the line numbers updated.

After that, if IntelliSense still gives you still get red squiggles, then this is an IntelliSense problem. You might have to wait until IntelliSense picks up the changes, or force a refresh.

If you get compile errors, this is a different issue and we would need to look at that as a separate concern.

Steve

Thanks Steve, I hope this won’t become an issue later on.

Hi,
I’m having the exact same issue: intellisense puts red squiggles in my code while I can successfully compile.
This makes it difficult/annoying to write code because it looks like there are errors, but there actually aren’t…

For the moment I will set “Disable Squiggles” on “True” in the Visual Studio Intellisense options.
This will no longer show the red lines, but actually I’d like to have those red lines present, but only if they appear correctly. If anyone knows how to fix this, please let me know =]

OK so I found the solution here
Changing between “Development Editor”/“Development” and compiling solved the false positive errors for me!