Can I use a primitive type for a UPROPERTY?

You definitly can use primitive types. Are you decorating your class correctly with the UCLASS macro?

I would like to expose a C++ “bool” primitive data type to blueprints so that I can check/uncheck the value in the editor, and based on Epic’s documentation, it looks like I can use a primitive data type (bool, int32) as a UPROPERTY. When I try, however, I get compiler errors which vary depending on what primitive type I use. Given that the errors are not consistent, I’m either missing a step, or one cannot, in fact, use primitive types this way. Can anyone help?

Hi Dijon, you certainly can use primitive types as properties. Make sure if it’s editable that you also specify a category, like this

UPROPERTY(EditAnywhere, Category = MySettings)
bool MyBooleanValue;

Also make sure the property is either public or protected.

I hope this helps.

Hi Alderbit,

I tried it that way, and it fails with:
error C2659: ‘=’ : function as left operand

If I change bool to int32, then it fails with:
error C2661: ‘UIntProperty::UIntProperty’ : no overloaded function takes 3 arguments

I must be missing something important.

Do you have a #include “YourClassName.generated.h” at the top?

Have you tried a clean and build?

Can you post some code?

Hi Michael,

Yes, I used the editor to generate the class to allow it to create the necessary boilerplate code. The class compiles and builds without problem, but when I add UPROPERTY(), UPROPERTY(EditAnywhere, Category = MySettings), or UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MySettings), for example, then the build fails with errors similar to those that I posted in my comment to Alderbit’s response. Any other ideas?

Yes, the generated file is present.
Yes, I tried clean and build (a very slooooow process), but no change.
On a whim, I decided to rename my variable from isSelected to bSelected and it compiled. I went back through ACharacter, AActor, APawn but only found in UObject the property IsSelected (note the initial capital ‘I’). Could this be the cause? I wasn’t aware that a similar property existed but, even then, C++ is case sensitive, is it not? While my code now builds, I would really like to know why it failed. Can you help?

Blueprints might not be case sensitive - so autogenerated methods clashed? That’s probably it as IsSelected() is a function - so the below messages about ‘function as left operand’ and your bool taking 3 arguments make sense.

Thank you VERY much for taking the time to help me sort this out.