How can I create a Blueprint Exposed Public access read-only, but private access read/write UProperty ?
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, Atahan Bozkurt
asked May 13 '16 at 03:00 PM in C++ Programming
Make accessor/mutator getter/setter functions in the blueprint.
Other stuff requires going C++ mode on it.
In C++: UProperties cannot be private. Use BP method.
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:
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.
answered May 16 '16 at 07:24 PM
Zhi Kang Shao
If I'm understanding correctly what you want, then this should do the trick for blueprints.
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 :-)
answered May 13 '16 at 04:09 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here