What is the difference between “get” and “set” when blueprint scripting, and what are some simple instances I would use one versus the other?
I’m certain this is a fairly simple question, and I’m looking for a simple, easy to understand answer for novices like me just getting introduced to blueprint scripting.
Get is retrieving a value, checking what it is. Set is assigning a value to variables.
simple instances I would use one
versus the other
The difference is the same as with reading (get) and writing (set). You wrote this post (set) and I read it (get). I also responded by setting this very text field to what you’ve just read (get).
I guess I technically understand, but the verbage is confusing. Take this blueprint for example. It’s just adding two floats to display a value. Now my “get” variable is 9.3, but I had to set the value to 9.3 in order for it to be that. Otherwise there would be no value to check, aside form the default 0.
Meanwhile, the “set” variable on the right is just referencing (or getting) the value of the addition equation. I didn’t set anything for it.
When you create a new float variable the engine “initializes” (gives it a value as a default, just so that you don’t accidentally crash the engine trying to use the variable when it has no value) the value to 0. When you “set” it to 9.3 in the editor by typing that number into the box you replace the default “0” and now your default value will be “9.3”. Anytime you use this variable it will start at 9.3. If in the course of game play you wish to change this value say it is your player’s health and the player took damage…you would first “get” the default/starting value of 9.3 and then “set” it to a value of 9.3 minus damage. In your example you used addition but you could have subtracted, the output pin will be 9.3 - X let’s call it 5. So the output pin will equal 9.3-5= 4.3. However, your variable is still equal to 9.3 if you were to use it somewhere else in the blueprint. Until you connect the output pin whose value is now 4.3 to a “Set” node of the variable you want to change the variable will remain at its default value (9.3). Once you connect it to a set node, the value of the variable will forever be 4.3 until you set it again to something different. Now if you were to use that variable somewhere else in the blueprint it wouldn’t be 9.3 anymore but 4.3. When you quit the game and start it up again, the variable will have returned to its default value of 9.3. I have a bunch of very beginner friendly blueprint tutorials that I think you will find helpful at this stage in your learning. I go over things like variables, casting, references, funcitons etc in a very easy to understand format.
So instead of saying I “set” the value to 9.3, it is more accurate to say I “assigned” the value to 9.3. But wouldn’t I have actually /set/ the /set/ value to 10.3 since I referenced it to the value of 9.3 plus 1.0?