GET SET...GODOT! Use the Revamped Setter and Getter Functions

preview_player
Показать описание


-------------------------------
🖈 *MENTIONED LINKS*
-------------------------------

🖋 *SYNOPSIS*
Learn the new syntax for setter functions and explore two examples: Updating player health in a health bar and setting the color of a character in the editor.

#godot #gamedev #gameengine
-------------------------------------------

*CC-BY 4.0 LICENSE*
Рекомендации по теме
Комментарии
Автор

GDQuest is one of the pillars of the Godot learning community. Nothing but love and respect tho GDQuest crew.

computersciencestudentriverbat
Автор

Great video.
I use setters and getters extensively for tool scripts, to get the results live in the editor, but it is important to note that the variables set in the editor are set before the node is in ready state, so if you just blindly try to apply values to children of the node, you will get a ton of errors.
You need to check if the child node exists, then check if it is inside the tree and only THEN apply the new values.

Putting all this boilerplate code inside every inline variable definitions can make the variable section of a script huge, defeating the purpose of inline setters and getters, so this is where using setter and getter functions are handy.

Mostly I use inline setters, but put the child node update scripts inside functions, that I call from the inline setters.
It only adds a single line of code to the setter, so the clutter is minimal and it's easy to comprehend when every setter ends with a function call like update_label(), update_material() etc.

JakobKobberholm
Автор

i think one useful and potentially common usecase for the getter function is actually to combine exported variables. having multiple/duplicated exported variables creates a neater interface for your designers, while combining them stops those multiple/duplicated variables from creating excessive/confusing code for your programmers.


An example:
You want to recolour a character, as is shown in the video, or is done in a game like Halo, but that character has an albedo texture.
Instead of always recolouring the albedo texture after getting the texture, you can write the getter function for the texture, such that it always returns the recoloured asset; assuming you will always want the recoloured texture. (Which is likely, in the case of Halo.)

Though, i think that in modern times, it would probably be faster for the GPU to handle the recolouring, so you would likely want to stick to combining variables which are not graphical.

pie
Автор

love your thumbnail designs. their esthetic is pleasing my senses

danielakomski
Автор

I literally just struggled with these when using them for the first time 2 hours ago, and then i see this video 😭

nintySW
Автор

I love your videos! Dont stop please, I'm learning a lot 😊

Weahl
Автор

Getter and Setter is a classic concept in C# so I am sure the See-Sharpers out there would try using this in Godot.

seyproductions
Автор

it's just keep getting better and setting things good for me

ThunderPlayStudios
Автор

The export really reminds me of unity, I think it's nice to have

DieDona
Автор

I would love to see videos on Godot's 3D IK system and how to head track a target.

RaveYoda
Автор

I usually don't bother with getters and setters in any language that has them unless I need to do something special when variable is read/set.

UltimatePerfection
Автор

always wondered what was the real purpose of setters and getters outside of java/c++ haha

rios
Автор

You can write Get or Set only is really convenient. I remember when I used Unity, I had to write them both.

rocketpython
Автор

What scenario would you want to have "set_health" directly which then references new_health against current_health?? Surely it would be better to use a "delta_health" function with requested change argument (ie -10 is 10 damage) so that the health function itself is fully in charge of what new_health should be... as well as calling external things conditionally such as death functions. That's why clamping and animations are in there, after all.
This also adds functionality for things like armor reducing damage taken that you just don't need to manage externally in the enemy's code from player's properties.

Terminarch
Автор

I have a question... But I don't know how to make it simpler...


Let's suppose I have a "health" value and its "set_health" function, what's the difference of binding the function to the set property than not binding it?


Maybe I'm just confused about something that wasn't clear on the video:

If I want to set a variable that has a set function, do I need to call the function of the variable or setting the value through operators calls the set function?


I hope I was clear, my programming vocabulary in general is terrible.

FernandoBroca
Автор

It's great for addons too, documentation and convenience in updating the editor

michaeljburt
Автор

I've been chiseling away with a dull nail it feels like at all the Godot knowledge.. I actually watched this video a year ago before starting the GDquest courses, even now, it's difficult to wrap my head around. But I think I get the format at least, and really like the 2nd way setters can be laid out. Feels less confusing. #commentforcommentssake

jakerosper
Автор

Can you please make a tutorial for a platformer dash? The other tutorials only have dashes that work when you move

Slapthesushi
Автор

I'll try it out myself later when I get the opportunity, but I assume these set get functions are also called when accessing variable properties. For example, if I have a setter for a Vector2 and I type:

var my_vector: Vector2 = Vector2(1, 1)
my_vector.x = 3

It will call the setter fuction with the argument Vector2(3, 1), right?

unnamedtoaster
Автор

is using get/set a better practice than signals?

S.Korolev