Unable to find 'class', 'delegate', 'enum' or 'struct' with name TRange compilation error

I am trying to declare a UPROPERTY variable of type TRange, so that the user can define the lower and upper bound of a float range.

In my build.cs file I have “Core” included in the public dependency module names; and “CoreUObject” in the private dependency module names.

Then in my includes I have:
#include "Math/Range.h"

And the declaration I am writing is like:

UPROPERTY(EditAnywhere, Category = Range)
TRange<float> Range1

But I am getting the following compilation error:
Unable to find ‘class’, ‘delegate’, ‘enum’ or ‘struct’ with name TRange

Any suggestions?

5 Likes

Unfortunately you can’t do that. Except for a couple types, templates aren’t compatible with UPROPERTY.
The thing to check with that sort of error is to always go to the type declaration and see if it has a UCLASS/USTRUCT/UENUM macro. UPROPERTIES require one of those in order to match up the reflection data of the property to the reflection data of the member. If the type isn’t reflected, it can’t be a property.

7 Likes

Try

UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = “15.0”, ClampMax = “50.0”, UIMin = “15.0”, UIMax = “50.0”))
float testFloatRange = 15.0f;

This limits the float from 15 to 50

If I try that I get the following error:
Found ‘g15’ when expecting ‘,’ or ‘)’ while parsing Variable specifiers in Member variable declaration in class ‘MyclassName’ Myprojectname.

I am using unreal engine 5.1

Paste the uproprty declaration. You probably have a typo in the code.

This doesn’t cover the use case above, which is asking for a range variable that denotes a user defined min and max value. Your example is a float which is clamped by a hard coded range.

If you’re looking for a TRange that can be a UPROPERTY, try the FFloatRange struct. It isn’t documented very well, but it functions near identially and in editor it has a nice property UI. You can also make either side inclusive, exclusive, or open like you would with a TRange.

Hope this helps someone down the line!

image