G4m4
(G4m4)
March 26, 2015, 3:29pm
1
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?
Astronovice
(Alexandru Pană)
September 15, 2015, 7:19am
2
Vawx
(Vawx)
June 23, 2017, 2:53am
4
It’s const but you didn’t give it a value. Maybe that is the issue?
WHSolv
(WHSolv)
June 23, 2017, 3:38am
5
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.
Vawx
(Vawx)
June 23, 2017, 3:57am
6
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
WHSolv
(WHSolv)
June 23, 2017, 5:08am
7
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.