I’m using Unreal Engine 5.4.3 and I have a question about AllowPrivateAccess.
I know that AllowPrivateAccess allows a BP access a private variable. But, I can set that C++ variable public instead of private.
So, I think AllowPrivateAccess is used with Blueprint’s related variables, such as a UStaticMeshComponent field.
Under what circumstances is it advisable to use AllowPrivateAccess?
Maybe, there is a convection about using AllowPrivateAccess. Or make anything marked as UPROPERTY protected (someone said me that this is a convention).
I don’t know if I would say there’s a convention per say as I think it’s more a matter of taste/style. I’m of the opinion that if you truly feel that the class variable should be private, then don’t play tricks and expose it to BP. Instead create setter and getter UFUNCTION’s which are BlueprintCallable.
That said I’m open to be schooled on a viable edge case. If I was looking for convention I would probably dig through the engine source to see when/where they use it and if it’s applicable to my use case.
EDIT: Maybe some food for thought. I don’t have the editor in front of me so I can’t try this but what happens when you have a private member variable and you create a blueprint subclass? I realize it’s a subclass but maybe that would be a moment where you would want to allow access via BP?
It is only required if you want to make a c++ property private within c++ but allow blueprints to read and or write to it.
Making a Getter or Setter BlueprintCallable UFunction will not prevent other Blueprints from calling it as BlueprintCallable UFunctions are public by default.
You can however use the meta specifier BlueprintProtected = true to make a UProperty or UFunction protected in Blueprint so only derived Blueprints can access it.