all right in this video I want to talk
about the concepts of using get versus
set in variables now for most of you if
you have any sort of programming
experience whatsoever or even if you've
been playing in Blueprint this is going
to seem really obvious but there are a
few instances where using get and set
can be a little tricky so I do want to
make sure that we hit on this now there
are two different things to keep in mind
when using get or set if you're doing
something like a math operation on a
variable you'll probably have to use
them both and I want to give a quick
demo of that so here I have a very
simple blueprint that has nothing but a
billboard in it so I can see it if I
drop into the level and I'm going to do
a few things some of which are a little
dirty but they will help us out I'm
going to jump over to default and I'm
going to uh set autore receive input to
player zero that just means I don't have
to worry about any special input
settings and I can just make stuff
happen for testing purposes I'm going to
right click and tap the E key and create
a uh an input event for when I press uh
the E key on the keyboard what are we
going to do well let's start off by
creating a variable and I'll call this
my int and let's take its variable type
and I'll set that to integer so this is
a number that does not have a decimal
point and what I want to do is make sure
that whenever I press the E key we are
going to increment uh the value of my
int so the first time I press it it
should be one second time I press it it
should be two and three and four and so
on and so on so let me compile my
blueprint and you'll notice that default
value for my int is zero that's perfect
I don't need to mess with that at all so
to perform math on this I need to get
whatever is already in my int and I need
to add one to it so I'll start by
dragging this in like so and in the
first case the first thing we need to do
is say what is your current value well
whenever you're getting that current
value when you're asking for that
current value you need a getter so we'll
bring in a get then we need to perform
our math operations so we'll say plus
and we get integer plus integer and
we'll just add one to
that now we need to take whatever the
end result of this math equation is and
we need to use that to set a new value
for my int so I'll drag my int back in
and this time I'll choose set now notice
set requires an execution input it's not
enough just to feed this data I need to
make sure that it executes as well so
there we go now this will not show us
any meaning result in the view so the
very last thing I'm going to do is drag
a wire from my little math problem out
here into space and I'll type log
actually log is not going to work when
you drag off of a wire like that so let
me just right click it open space and
type
log and all this is going to do is print
some sort of a string to the screen so
I'll make sure those are connected and
I'll drag a wire over this will
automatically create a conversion into a
string so that that will appear on the
screen with just that done let's compile
I need to make make sure a copy of this
blueprint exists Somewhere in My Level
and then we can
play and when I hit e you see already at
the top we've got two three four
five like
so so very quick and easy we are
performing a math operation and you see
that number steadily incrementing now
that's easy that's super quick super
simple but what happens when we need to
set a property on an object that exists
somehow in our level now this can be a
little bit more difficult to show so
bear with me uh I'm going to grab an an
already existing blueprint uh let's grab
my
character and I'm going to jump over to
uh the construction script for the
character now this character has a mesh
and we can't see that me that mesh
listed in the my blueprints panel unless
we check show inherited variables so
this is a these are some variables that
were set up in the parent class for this
object so we're going to grab that mesh
and we're going to get it and we want to
get some information from that so we're
going to say get
material like so now I should also
probably jump over into my components
real quick let's take that mesh and
let's double check the material applied
to it so we're probably going to have to
jump all the way down to the skeletal
mesh and we'll go ahead and close the
tutorial window let's go over to uh the
materials in mesh details we'll double
click that and we have template master
and we notice that that has a vector
parameter called diffuse color well
that's perfect that's exactly what I
wanted to see I just wanted to know what
the name of that uh parameter was if
there was such a thing now because that
has a parameter we can make a dynamic
version of that material and we can do
some changes to it so for instance uh
let's rightclick and I'll say actually
it's
create uh create Dynamic material
instance and we need to make sure that
gets connected to the construction
script and we're going to feed out the
result of get material into that now I
am going to store that Dynamic material
instance into a variable I'm going to do
this through the shortcut method of just
right clicking and choosing promote to
variable and I'll call this uh DMI so
that's short for dynamic material
instance so I can talk to that later the
last thing I need to do is set that uh
that proper or some set that material
onto the mesh now this is where things
get a little interesting I am
setting a property on that mesh but I am
not changing which mesh is stored so
what I want it may sound like at first
because you're setting the material that
you may want to use a Setter but that's
not the case what we're doing is we're
going to get the mesh because we're just
kind of talking to some part of the mesh
and then we are going to set the
material from
there again you might be thinking like
well why aren't we using a Setter a
Setter would be used if we wanted to
change out to a different mesh on all
together which is not what we want to do
so we'll go ahead and connect that and
then I can take my return value from
Dynamic material instance and plug it in
like so so there we go so now we have a
dynamic version of that material
assigned to our character now that's not
going to do anything particularly fancy
until we tell it to so here in sort of a
blank area of the event graph uh I'm
going to do a couple of things again
let's do something a little bit uh a
little bit hacky we're going to tell
this to automatically listen for inputs
which we probably don't have to do uh
but I'll do it anyway so we'll
automatically listen for uh input from
player zero and go jump back to the
graph so here in just a random blank
area let's pick another letter of the
alphabet on the keyboard we'll say F and
we can now talk to that Dynamic material
instance variable and here's the thing
you might be okay let's say we want to
assign a different color to that uh
again because you are setting something
in this case setting color you may be
temp Ed to use a Setter but that's not
what we want we want to get the material
and then set some property inside of it
so now we can say uh set Vector
parameter and it's going to ask what
that parameter name it should be diffuse
color but I can double check real quick
yes diffuse color all one word so we'll
just type that in diffuse color like so
plug this in and then to make a random
color a really fast way to do that would
be to uh choose uh so we're kind of
working backwards we'll drag a wire back
and choose make linear color and then we
can drag backwards from here and say
random and we'll say random float in
range and our range is going to be0 to
one and we just copy that and paste
it and paste again and we'll just plug
those into G and B there's another way
to do this with vectors but we're not
going to worry about that right now okay
so let's go ahead and compile notice I
hardcoded Alpha to one I didn't really
need to do that but it makes me feel
better so now with that out of the way
let's hit play and now if I tap the F
key we get a random color every time we
hit the button uh it's because we're
doing uh just a really quick random
check and we are assigning a new value
to the color property or the uh the
vector parameter but we did not do that
with a Setter the only reason we would
use a Setter would be if we wanted to uh
in this case we wanted to change out to
an entirely separate material or in the
case the construction script if we
wanted to change out to an entirely
different mesh so that is going to wrap
up this quick video over the difference
between getting and setting thank you
very much