Blueprint Getters and Setters

So I’m fairly new to UE4 and Blueprints but I’ve got a fair few years of games development experience.
I was wondering if making blueprint functions that act as getters and setters for things such as health is common practice with blueprints? I just want setting variables to fire events for things like updating HUD elements, etc and having overridden setters is normally the way I would go about doing so.
Basically, if I was to implement getter/setter functions for variables will I encounter problems later on with the way blueprints work?

Thanks in advance :slight_smile:

I often do this and have not run into any problems.

good habit stays as good habit :wink:

Awesome, thanks guys :slight_smile:

how exactly do you override a setter? just make a function named “set <variable>” ?

i havnt done that in bp. But i assume you first need to set the function in your Parent Blueprint to Public/Protected.

Maybe you can even set up “Is overridable” or something like that.

The result would be that inside your child bp you should see that function under the category you set in parent. And then right-click it -> implement function.

but like i said i only did this with OnKeyDown for inputhandling, which are based in c++

It used to be that you could just get a reference to a BP and directly set/get the variable but now I have to create get and set functions in the BP itself. I often just create a custom function in the EventGraph for a set but a proper function for a get

A built in way to create this duality would be nice, or to be able to set a variable as gettable/settable etc

" or to be able to set a variable as gettable/settable etc "

Well set up a variable and make it private or protected -> means its not visible to the outside.
Then create a GetVariableName Function

variabletype GetVariableName()
return myVariable;

this will do the trick. You can “Read” the variable from the outside but you are unable to set it from the outside.


This functionality still exists, just click on the eye symbol to make the variable public.