How can I create a Blueprint Exposed Public access read-only, but private access read/write UProperty ?

Hello all,

I want to create a private variable that can be accessed “read only” from other class / blueprints.

In traditional C++ I would create private and make a public getter function but I am not sure if it’s the true way to handle it in UE 4.

Is there a UProperty argument or specifier in UE 4 ?

Thanks,

Make accessor/mutator getter/setter functions in the blueprint.

Other stuff requires going C++ mode on it.

In BP:

In C++:
UProperties cannot be private. Use BP method.

Src: Properties | Unreal Engine Documentation

Also see this subsection:
https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/BlueprintReadOnly/index.html

If I’m understanding correctly what you want, then this should do the trick for blueprints.

    UPROPERTY(BlueprintReadOnly)
    type name;

For other C++ classes, you would need to make a getter function, as you regularly might.
I would recommend against making any variables private to the C++ codebase, but if you really prefer that style don’t forget to inline it :slight_smile:

I’ve made a accessor crosstable and I will upload soon.

In C++ you can declare a private UPROPERTY but you’ll get a compiler error or warning if you try to make it BlueprintReadOnly or BlueprintReadWrite. To get around this, you can specify explicitly that you allow a blueprint accessible variable to be private using this:

private:
   UPROPERTY(BlueprintReadOnly, meta=(AllowPrivateAccess=true))
   bool MyPrivateValue;

So that makes a private variable accessible in blueprint. (My preference though is to declare the UPROPERTIES protected, since making a private variable read accessible already doesn’t make it private.) To give access to it from other C++ classes, simply make public getter/setter functions.

1 Like

can you see what’s wrong with my code? C++ blueprint readonly properties now showing in blueprint editor - Programming & Scripting - Epic Developer Community Forums