What’s the thought process on making Blueprint variables Private and using Getters/Setters to access the variables in other classes or actors?
Is it the same as something like C++ where normally a class’ variables would be set to private? I rarely if ever see Blueprint variables set to private though, even in Example Content and it seems they’re always called directly.
I think I’m so used to creating a class with Private (or Protected) variables that it’s throwing me off to not do it.
What is the general perspective on this? Should Privates be used with custom Getters and Setters or should variables be directly called?
I don’t know about the general perspective but I can give you mine (since you asked )
I would advice against making trivial setters and getters.
If you need some additional work done when setting or you need to cache the answer when getting, please do use them but name them appropriately. (in which case they stop being just setters and getters)
In Blueprints I use protected functions and variables only to prevent clutter of the right click menu but in that case I don’t expose them at all. I often have multiple public events calling the same protected function with different parameters.
I tend to make variables private when a bunch of other functionality needs to happen whenever the value is changed.
By forcing functionality to run through a setter, I make sure that I can’t accidentally change a variable’s value and forget to update any systems that may be reliant on that value.
A common case for me is when I have two things that I want to keep references to each other.
For Example: By forcing the scripter to change a player’s team value through a setter, I can make sure I don’t accidentally ever try to change the player’s team reference without also informing the team that their members have changed.
I find this doubly helpful when working on projects in a group. It makes sure another scripter doesn’t need to know about all the systems that rely on a variable before that scripter can make use of the variable.