Const UProperty specifier unknown

Hi!

The “const” specifier for UProperties is unknown to UHT:

USTRUCT()
struct Foo
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY( Const )
    float Bar;
};

In TemporaryUHTHeader_Foo: Unknown variable specifier 'Const'

Is there any reason for it, is it a legacy thing?

I have the same question. According to this: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/Const/index.html the Const specifier is valid for UProperties.

Nothing new so far?

It’s const but you didn’t give it a value. Maybe that is the issue?

What do you mean?
If you are talking about default value like this

UPROPERTY(Const)
float SomeFloatVar = 1.f;

then it doesn’t work either.

You’re totally right. I looked into the ObjectMacros.h file and looked for “Const”. It is strange because under:

	// valid keywords for the UPROPERTY macro

There is a Const.

I do not know why it is giving a compile issue. Must be used in a specific way in which I am not sure of.

Edit:

Here is a thread where a developer explains there is a limitation with this keyword:

https://forums.unrealengine.com/showthread.php?55244-UPROPERTY-and-consts

Here is a Wiki where it explains that Const causes a compiling error and to use the “Visible*” specifiers instead.

https://wiki.unrealengine.com/UPROPERTY#Const

Yeah, I saw these links. And the right point of one of the comments in the first one is that a variable, being exposed to BP, shouldn’t be changed anyhow neither inside C++, nor in BP. Yes, VisibleAnywhere, for example, provides read-only access in BP, but does absolutely nothing with C++, and that’s the problem.

One of the “solutions” is make a UFUNCTION getter for non-exposed const variable, but it looks like a duct tape.