USTRUCT - Problem with GENERATED_USTRUCT_BODY()

Hey Guys,

I got some really strange behavior of VS / Unreal4.

  1. I have a defined USTRUCT in one of my header Files.
  2. VS compiles without error or warning but underlines 2 parts of my struct in red.

This is my struct in my Header.



USTRUCT()
struct  FWave
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		TSubclassOf<class AActor> SmallEnemy;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		TSubclassOf<class AActor> NormalEnemy;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		TSubclassOf<class AActor> BigEnemy;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		int32 NumberSmallEnemy;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		int32 NumberNormalEnemy;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		int32 NumberBigEnemy;

	int32 getNumberEnemies(){
		return NumberSmallEnemy + NumberNormalEnemy + NumberBigEnemy;
	}

};


And in my UCLASS I define an array of the USTRUCT.



UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)		TArray<FWave> waves;


Even without using the USTRUCT in my .cpp there are red underlines.
The problem seems to be generated by the GENERATED_USTRUCT_BODY() - Part.

Any thoughts? Sadly it’s really necessary.

Thanks for help.

Jack

You can ignore the red underlines. Some of our types and macros are fairly complicated, syntactically, and Intellisense doesn’t always know how to deal with them.

For coding style I would recommend that you place the UPROPERTY macro and the property declaration on two separate lines, i.e:



UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Waves)
TSubclassOf<class AActor> SmallEnemy;


The Problem is BP then. Cause in my BP I define Numbers like 1, 2, 3 and enemyClasses. But with debugging it seems like I get Numbers like 330423415, 0, 11120390339 instead. Pretty strange stuff.
Anyway, now I know I have to find the source of the problem somewhere else. Thanks!

I really cant figure out where the problem is. It’s really hard to explain what is wrong, cause the behavior of VS.
If I debug the session, at some point i get the correct values from BP and the USTRUCT. But now VS is running crazy. Its jumping wild around when i slowly debug.

i.e:
Breakpoint is outside of an if-condition.
It goes into.
In the middle of the condition it jumps out into one else-condition.
Then it jumps out to the start of the function again.

In all the years i never saw this befor. Do u have any experience with this?

I made a work around. Still no idea why that is happening. Hope Intellisense get better over time.

Having big problems with this my self. Would love to hear how you worked around this

Sorry for replying to an old post, but for anyone else looking for a workaroumd

#ifndef __INTELLISENSE__ /* Eliminating erroneous Intellisense Squigglies */ 
GENERATED_USTRUCT_BODY()
#endif

Ditch Intellisense, and get a copy of Visual Assist X. It’s probably the only reason I know as much about C++ as I do today, and can program half the things I do in record time. How anybody programs in Unreal (or any software for that matter) without it is beyond me.

As for the numbers you’re returning, make sure you’re not mixing between floats and integers in a weird way. It’s not going to be anything to do with V or intellisense if you’re debugging and actually running your code, it’ll be a problem with your code.

Sorry as well for an old post, but this was the most recent search result. I’ve got a similar problem, except the problem isn’t with Intellisense, so the work around doesn’t help. In my case Intellisense is not false reporting, but accurately predicting compilation failures.

I’m just following the example here: Data Driven Gameplay Elements in Unreal Engine | Unreal Engine 5.3 Documentation

A lot of the identifiers are reported as undefined, starting with:
Error (active) explicit type is missing (‘int’ assumed) (Line 2: USTRUCT(BlueprintType))
Error (active) identifier “BlueprintType” is undefined (also Line 2)
Error (active) identifier “GENERATED_USTRUCT_BODY” is undefined (line 4 in the link)

Even:
Error (active) identifier “UPROPERTY” is undefined

That last is particularly odd. The error triggers on the 2nd one, NOT the first occurance. UPROPERTY is recognized with the first occurrence. Only after that, it and all its properties are reported as undefined (even when they’re exactly the same).

There’s so much reported wrong (including missing { or ; where none exist in the example) it leads me to wonder if this code has been deprecated, or if the example is otherwise out of date. However, the structure matches the OP’s post, except for unimportant line returns in the example, so I expect it was correct at some point in time.

Edit: Found some updated code here: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

Even though I’m using 4.12.2, I tried it. However, doing so results in GENERATED_BODY being reported as undefined. So, no real change in behavior.

These errors will ultimately come down to a mistake somewhere in your code, probably just one, but it causes all the macro stuff to break down and look a lot worse than it is.

Make sure your class names have the correct prefix, your generated.h header is included, you’re using the appropriate GENERATED_XXX_BODY macro for the type etc.

Oh, and if in doubt, close your project, right click on the UPROJECT file and ‘Generate Visual Studio Files’, then re-open.