Function Chaining Tutorial in Godot 4.x
Вставка
- Опубліковано 8 лют 2025
- Thanks for watching my tutorial video on function chaining in Godot 4!
If you are interested in taking a deeper dive into the Godot game engine you can check out my other courses at this link: www.heartgamed...
Thank you all so much for your support!
If all you need is to initialize, then create custom _init(args) function and pass arguments into new( args) when creating new instance.
Hey! Great question. I think I picked a bad example for the video because passing the actor into an _init() function makes perfect sense. This pattern is better suited for optional parameters. Something like the start of the video with the create_tween() function shows a better use case since those parameters are optional and have default starting values.
The intro never gets old
It gives me nostalgia
Glad you are back making yt video !
Heartbeast!👋glad to see you and your lessons again.
new banger just dropped
So sick. Never thought about doing this
The goat is back
saving this to watch later
This is usually called the "builder pattern" in non-game software.
Thanks for letting me know! It's probably called that in game software too. Now I can use the correct term for it.
This is incorrect. Builder pattern and function chaining are not the same thing and has two different meanings. Function chaining is just function chaining this is a principle that comes from functional programming. Meanwhile builder pattern is an OOP principle and is different, here your taking the object you want to end up with and setting its settings directly while builder pattern has a different object whose soul purpose is to configure and create instances of the desired object so you might have MoverBuilder that you can configure which will create a Mover using .Build() with the same settings. Both principles are mutually exclusive
He's back
and with facecam no less
👍🏼
Master!
Why not override the _init-method so you can pass the arguments upon creation
Good question! That can work too but it's not as readable and so I prefer chaining. There are also a few other tradeoffs (since chaining allows you to choose which properties you decided to pass in on creation).
Came here to make a similar comment. In this particular case, where the Mover needs an actor to work, and will fail in runtime if one is not provided, I'd ague it's more idiomatic to pass it via constructor. But chaining could still be valuable for more "optional" parameters (such as of looping/easing behavior in tweens).
@@watchagoblin Really good point! The example I picked to show the pattern isn't a great one and is causing some confusion. I do still like how readable it is, though. It's hard for me to let go of that even though I agree with your point.
@@uheartbeast Just to be clear, I still think the video is a good breakdown of the technique, and helpful in that regard! I think most programmers will be able to abstract away the specifics of a toy example, and focus on what the pattern itself enables them to do.
@@uheartbeast I think it'd be great if you can append this note in your description so people don't get confused or have to scroll through the comments to find this.
This is slightly incorrect. Function chaining IS NOT builder pattern. Builder pattern is when you have a class (or just any form of object) whose task is only to instantiate complex objects. Like take the thumbnail for it to be the builder pattern you would make MoverBuilder and when you call .Build() on it it will return a Mover with what ever settings you defined on the builder. Function chaining and builder pattern is usually used together but that does not mean its the same thing
Thank you for the clarification. I'll update the title.
I don't understand the way you are instantiating. why not use _init() within the class and create the instance as className.new(...initial_props) ?
Hey! That's a good question. I'm going to copy paste my response from a different comment.
I think I picked a bad example for the video because passing the actor into an _init() function makes perfect sense. This pattern is better suited for optional parameters. Something like the start of the video with the create_tween() function shows a better use case since those parameters are optional and have default starting values.
@@uheartbeast I guess that's fine. There can be different implementations for the same thing. Nonetheless you can still use the _init() constructor with optional parameters by specifying default values.
hi :)
Any update on any games or have you stopped working on everything?
Released a demo for WASarD on Steam and I'm still working on it. I'll don't have anything big to announce yet.
@@uheartbeast Glad to hear it man, sending good vibes and hoping it's going well, you've got a lot of talent
@@uheartbeast Oh good to know. I've had it wishlisted for some time now, will have to check out the demo.