I love that you managed to explain a fairly confusing and complicated topic with examples showing both the problem and the solution by using this approach and also the tradeoff for using the inheritance over composition ( at least for this kind of scenario ). I think those are the kind of educational videos that are hard to come by, especially with an easy to follow visual representation, which are really appreciated by the community. We know it's not easy and it takes time to find examples and then explain them in a simpler manner, as you did, but we really appreciate each one of them and we thank you for that!
I agree, thank you for going into examples that are very applicable. Here and there I'll watch some coding videos that give useful advice, but they don't provide any examples and I have no idea what to do with their advice because I have to spend extra time figuring out what it means and how to apply it.
Amen! As I was watching I thought to myself I need to compliment this man's fantastic teaching ability. Then I scrolled down and found you've done it better than I could have. Well said. Bitlytic thank you for such a clear and simple explanation of the different concepts and providing an example, you made it very easy to understand and follow.
came here from Brackeys and so glad i did, GREAT video. loving where the game Dev world is going, feels like a new era that is far more enclusive than ever before
cool video! if you are already trying to decouple code using composition over inheritence, i would probably create a signal on the hitbox that the parent object would connect to. then whenever the hitbox gets hit, it emits the signal, the parent can then decide what to do with it. in this case propogate the attack info onto the health component. this way the hitbox component does not need to know anything about the health component.
Very much agree, signals and composition work so well together but I figured I had already given enough fundamental info in the video or I would've included that. Specifically I would've replaced the queue_free in HealthComponent with a signal emission that the player can choose to use or not
@@paul_musique I'm not really sure how to explain the signal system just in a UA-cam comment, but I recommend checking the Godot documentation, it explains signals really well
@@paul_musiqueYou don’t need to use a parent for signal emissions. You just need an acccessuble entity to connect to. Many godot tutorials use a “global” or “manager” script that contains their most common functions / signals which they can emit to from any script or object.
This has to be one of the most (if not the most) approachable explanation of inheritance vs. composition. Very easy, straight forward and clear. I had to learn it the hard way and for the longest time couldn't understand the advantage. I wish I had this video back then. Love it!
@@YammoYammamoto idk man for me these kind of explanations just confuse things more. Its such an abstract explanation to the point its hard to visualise how it would work in code.
When I develop in Godot, I often use a mixture between inheritance and composition, and oftentimes, I use resources instead of nodes for composition since it is easier to modify through an export statement. For example, I have a slew of statemachine resources that I can plug in to my Actor class (which is basically an entity class), which makes it easier to trade behaviors depending on the entity type and whether there is currently a cutscene or battle.
I kind of got deeper into godot recently and I'm using custom resources unaware of this video's specific subject. I find it very weird that custom resources aren't being heavily promoted by tutorials. Need the same enemy to have different types of stats or damage, just drag and drop. It's like secret godot magic because there's only like 3 decent videos about it. What going on? I ctrl+F and this is the only comment talking about resources O.O
@Pulse_Skeleton Yeah Ik, weird right? You'd expect this miracle solution to be talked about more. It's so useful for, say, making multiple unique character objects in game from the same Actor scene without having to make seperate actor-inherited scenes for each character.
@@lunaticwyrm4675 is there a way to get type hinting for resources? Can they expose code to their holder? can I set default values for them in scenes and have those values hold when I instance those scenes without having to fiddle in the editor for each one? I've been trying to expose precise constraints from gdscript to the editor so it's easier for my team to use my modules, but I find nearly everything tedious to configure outside of a textual format (which prevents getting good adjustment/previews/feedbacks/hints in the editor).
This clicked for me. Was trying to learn this topic and you explained it so well in such a quick but well paced manner, never stop teaching, this was amazing
Composition as a design pattern I think is uniquely equipped for solving problems and making more robust (and easier to maintain) code. There aren't a lot of videos on programming patterns in Godot and seeing this is great. Talking about general/generic problem solving I think helps beginners out a lot by helping us step outside of "How to do X" to thinking about breakdown solutions to fit their own needs/program. Tutorials have their place and purpose of course, but I think Godot (programming in general to be honest) is in great need of this sort of problem solving/design thinking sort of information. Great video!
Your tutorials are so good. There's plenty of beginner tutorials for Godot at this point, but we are seriously lacking in simple guides on how to architecture games. Tutorials like these are incredibly valuable and many budding game devs wont even know that they need to be looking for this kind of stuff. Please keep making tutorials!
Coming from Unity where you can throw multiple scripts on things without thinking or use multiple inheritance, this kind of helps me get my head around how Godot is 'meant' to be used! Good tutorial.
@@kurushimee they actually do. Spaghetti code leans into massive super classes bloated with a lot of functions and huge objects that aren't properly managed in the memory by the program. So, even tho they aren't automatically making your code laggy or bloated, the usage of inharitance leans into this kind of problem really easily and it gets really hard to manage the memory usage of such objects.
Excellent tutorial!! This is one of the most concise explanations of the Inheritance versus Composition concept I have seen. The fact that you separate the theory from the later example makes it all the clearer
This describes exactly my struggles. I’ve been trained in Object Oriented languages like C++ and Godot’s implementation is really challenging the way I think about this stuff. Thank you so much!
Easily the best godot tutorial on this entire website. It's so clear and to the point. Who knew that you could teach me how to clean up my code in 7 fucking minutes?
The first video I found on this topic was the epitome of the "Every programming tutorial" meme video, but your video made everything click in my head immediately! Thank you so much for explaining composition in a quick and easy-to-understand way!
I come back to this tutorial every now and then just as a refresher. Each time I pick up a little more of the details. Definitely worth coming back to.
Damn, just found out about your channel and you do a very good job explaining these kind of topics (classes, inheritance vs composition). The Godot community needs more content creators like you
I've been working as a software engineer for more than half a decade and this is by far the best explanation I've seen for Composition. Nice video, keep it up!
I've watched like five videos from different people about composition, and this one is, by far, the most demonstrative one about why exactly composition is better than inheritance. Many congrats and thanks and praises for such a good work of topic telling 🙏
Best video ever, and this is not just for Godot 4, this works well for Godot 3 and mainly other types of programming if you get the logic behind it. Perfectly explained and simple. Absolutely brilliant
Great video, not only displays composition trumps inheritance in a lot of cases (inheritance has it's use cases) but also ties into how the workflow in Godot is awesome with it's Nodes system.
I really like how clearly and concisely you described the two strategies and how composition can be a preferable way of organizing your code. I look forward to more videos from you!
I always love seeing how other developers perceive and approach different problems, even if we both come to the same solution. It definitely helps when you make a video that's as well presented as this one! Great work
You explained this so elegantly. I've been trying to wrap my head around HOW exactly I implement an ECS in Godot, and I finally get it. Thank you so much
I just started with Godot. This is a really great tutorial. I was just trying to reformat my code and see what other people are doing and this is exactly what I was searching for. Your videos are very valueable to me :) Keep up the good work.
I've been using Godot for a good few years now and I have never thought of this for some reason?? This was such a fun and informing video!! I'm excited to put these concepts to use.
What makes godot more challenging for Abstraction and keeping code simple, is all of the different ways you can maintain variables- Sometimes it’s beneficial to assign a variable @ export , but there are also ways to usually do that programmatically. Sometimes referencing a node with $ is beneficial, but it can also be avoided altogether… Those practices aren’t normally an issue during programming in other languages (some languages do have “too many options” as far as syntax, with their own niche behaviors for each option, but godot does that on steroids).
nah im halfway in, and i already know this deserves at least ten times the views that it has just for the quality and the amount of work behind. great video!
YO this video was awesome. love the pace & effictiveness. you showed off a lot of stuff i needed to learn to start using godot properly and i thank you muchly for it :) into my obsidian vault this video goes!
this helped me alot, i've started using godot about less than a week ago, so far did not make my first game yet and this already gave me a good direction, thank you! however i noticed that when you got to this point in the video 3:29 you said "from the last video" without providing a card to click on(or a comment), as a youtuber myself i know that by time goes on it will be harder to search for the video manually, especially if you kept uploading videos, lastly i would really love to see a video talking about when and how inheritance is more preferred. thank you once again!
Just found your channel because of Brackeys' video! Great stuff, very well explained. I was getting into Godot and already used composition in project, but then things came up and I took a ~6 month 'break' and wanted a refresher, and this was perfect. I'm glad to see more people making videos on Godot that are slightly more than 'basic' level, because it was very difficult for me to find before. Everything was super beginner level tutorials where you just copy them without much explaining, but I was moving on to more complex things. I see you have some other vids that look interesting as well, so I'm going to subscribe and check them out too!
Hey, you did excellent explaining the difference between Inheritance and Composition. Not a lot of videos take the time to utilize simple illustrations (and color coding elements such as Attack, Health, and Hitbox). Very helpful for visual learners. You're on the right track, and I hope you keep making videos. That said, I'll be sending this video to my aspiring game-dev friends when I see them inevitably copy/paste code. Also, that sprite animation at the end is super cute!
Thank you!! I was meaning to use a more component-oriented approach in my game, but I've struggled with finding out how to implement that properly. This video really helped me understand it better - the code examples were especially helpful!
Hey, so glad I found this channel. I love how you visualize these concepts and make it easy to understand. looking forward to see more of these videos. Keep it up!
Thanks! Will def start using composition in my games and see how it turns out I am surprised I was able to understand this since I am not that good at programming yet you did a really good job in explaining the concepts in a pretty short time, good job!
my man do you understand how hard it is to break down code theory to such an understandable and digestible format? you got a real talent for educating people.
A time ago I made a similar sistem that mix both inheritance and composition, but it had the same soul, I found it so cool, now I notice that other people are dicovering and making it in many ways, it is amazing.
As someone deeply rooted in plain old Java, inheritance has always been my go-to, but this explanation of component-based makes things very simplified. I'll keep this in mind for the future, thanks.
Kudos. Moving from Unity to Godot, I had some idea that I was going to need to shift my thinking from Inheritance to Composition, and there are plenty of people online telling me what composition is and the basics around it (like the first half of this video) but very few showing it in action with examples (like the second half of this video) Thanks for this
I still think that composition isn't better than Inheritance in big projects, it would get messy. And for the damage script he could have used an interface to do that. Inheritance is harder at the beginning, but as the project keeps growing, it makes your life easier. Composition is the opposite.
@@b-lotus5145And you can definitely use interfaces if you use the Mono version of Godot, and if not there's a hacky solution provided by someone here on UA-cam that I used when I was using GDScript.
Wow, actually went through 10 videos about OOP, trying to find a way to fix the issue of inheritance. And you were the one to explain so clearly and neatly. Thank you a lot.
Thank you for this. I keep hearing about how great composition vs inheritance is but really needed a super simple demonstration of it actually being done to really get it. Videos about the theory are great but some of us just need to see it done a couple times! Thank you!
This is quite literally exactly what I needed to be able to attack trees (resources in general) and enemies in my game. Thank you so much for the explanation!
This is really really good advice. This pattern just feels right, like how the named classes, exports, nodes and scenes are meant to be used together to create an efficient and simple architecture which corresponds to programming best practices, but in Godot
Very helpful, this is the way. I've never really been a fan of Inheritance patterns for the same reasons you stated where base classes often do too much, and moving that functionality somewhere else is a huge pain. Refactors end up eating all your time. It's awesome to see good Composition patterns applied directly in Godot here to see first-hand how useful it is. Thanks for putting this together!
Thank you so much for this tutorial! I only started my project and immediately got into inheritance hell when tried to change its order. Now rewriting what I have with this new technic. Your classes tutorial is useful too.
This is a really fantastic explanation of the difference between inheritance vs composition which I think a lot of videos on the topic miss. Generally they don't show the inheritance part and strictly talk about how to deal with composition, which on it's own is not that helpful. Great job.
For someone whho works with Java, I had my fair share of complaining about the abuse of inheritance and lack of real composition. You managed to explain it in a way that I can just replicate eithout sounding too technical. Thanks!
This video is the equivalent of an ice cold glass of water at 2 am! Thank you for the visuals at the beginning! I get hard concepts for visuals and now my brain is firing off so many ideas!!! 🎉
Thx, I'm currently switching from unity to godot, so explanations for design patterns in godot are really helpful. Great vid, had everything i needed for now
Great solution! I was currently implementing this approach and it's already working great. I was coming from an OOP background and when I was working with Godot for the first time, I was trying to inherit everything. Lol, it was too messy to deal with, and the inherited classes were not efficient. I have one suggestion though: Maybe instead of using get_parent().bla_bla(), you can emit signal like emit_signal("somebody_touched_this_hitbox", Area), and take context from Area if Area is a particular extended class of Area (Maybe it's an Area of Enemy, etc.). This approach would easier to manage I think. Edit: Yeah, exporting the Node2D and attaching it as a variable is also a better solution. You don't need to work with signals. Good job.
This is really fantastic work. You definitely changed my perspective on this and saved me from going off the deep end with inheritance as I'm learning gamedev :)
1:20 instead of inheritance of the whole scene, you can also inherit just the script part, then you don't need to worry about the base scene node. Script can also just inherit from the abstract base class, so it covers all the similarities between objects that for example: have collision
There needs to be more content like this on Godot better coding practices and templates that can be used for any game taught in this fashion. Friggin great.
Thank you, this really gave me visual pointers as to how such a system works. I am used to build similar systems from scratch but am still not used to the visual approach in contrast to doing it solely programmatically
This is so much better than all the videos proclaiming that composition is “better” than inheritance. Like you said at the end, sometimes one is better and vice versa, and you’ll usually want to use both at the same time
Great rundown! One thing to note: you can actually make the collision shape a child of the HitboxComponent still and edit the shape as normal, so you don't need to set the entire thing up in each enemy. A small change, but something doable that could save a little time and effort. :)
I still like the way unity allows multiple scripts to be added, over adding multiple scenes as a workaround, but this is seems like a good way to stay organized. Amazing explanation btw, Thanks!
Think of adding multiple nodes as adding multiple components. It's not quite the same as Unity, but helps align your thoughts. I think making separate *scenes* is overkill. See my other comment about class_name.
Only that in some cases the number of nodes I have on a scene is ridiculously cumbersome in comparison to how it looked in Unity. Of course the functionality is the same, but from a hierarchy viewpoint and bird's eye view, Godot's scene is really messy.
Excellent video. When I was developing my game in Unity for the first time, I made the mistake of using inheritance for everything. When I wanted to create a box that would take damage, it was all so badly thought out, that the best I could do was to inherit from "Fighter" to have the corresponding methods and references. So a box was a "Fighter", a bit ironic really. 😅 Now porting everything to Godot I will try to reformulate well all the code structure to components or as I call it (Place and run).
okay i found out how. btw thank you for making these. there arent that many tutorials that guide in coding in general instead of just specific coding structures
Very nice video, well done, well explained and useful. However I would recommend against splitting that much, you end up getting negative returns. For example, the hitbox can itself be the health component, until you actually need to split more (for most games, you don't). Choosing where to split should be driven by real-world constraints, just like your initial impulse to move away from class-based encapsulation. Always do the absolute simplest thing! Still, it's one of the best videos on the subject I've seen, I'll recommend it to people.
i was once working on a project where i needed to build my own mini game engine , and i stumbled upon a principal named an entity component system ECS , and it was one of the most complicated and challenging topics to comprehend , let alone to practice , i was in a rabbit hole for about a month trying to get the basics of it , and it was hell , but i managed to understand it so deep i found your explanation to be simple and understandable more than i would've gotten it a while back , sadly i stopped working on that project and just directly skipped into goddot
I love that you managed to explain a fairly confusing and complicated topic with examples showing both the problem and the solution by using this approach and also the tradeoff for using the inheritance over composition ( at least for this kind of scenario ). I think those are the kind of educational videos that are hard to come by, especially with an easy to follow visual representation, which are really appreciated by the community. We know it's not easy and it takes time to find examples and then explain them in a simpler manner, as you did, but we really appreciate each one of them and we thank you for that!
This man really spoke for all of us and nailed it
I agree, thank you for going into examples that are very applicable. Here and there I'll watch some coding videos that give useful advice, but they don't provide any examples and I have no idea what to do with their advice because I have to spend extra time figuring out what it means and how to apply it.
Amen! As I was watching I thought to myself I need to compliment this man's fantastic teaching ability. Then I scrolled down and found you've done it better than I could have. Well said. Bitlytic thank you for such a clear and simple explanation of the different concepts and providing an example, you made it very easy to understand and follow.
Agree, really well made vid, to the point but also very informational!
Has a...
Is a...
Uses a...
came here from Brackeys and so glad i did, GREAT video. loving where the game Dev world is going, feels like a new era that is far more enclusive than ever before
same
same!
hey guys
It really is
inclusive
This really clicked for me, the animations were super helpful to visualize abstract ideas and I really appreciate the walkthrough in the end
cool video! if you are already trying to decouple code using composition over inheritence, i would probably create a signal on the hitbox that the parent object would connect to. then whenever the hitbox gets hit, it emits the signal, the parent can then decide what to do with it. in this case propogate the attack info onto the health component. this way the hitbox component does not need to know anything about the health component.
Very much agree, signals and composition work so well together but I figured I had already given enough fundamental info in the video or I would've included that.
Specifically I would've replaced the queue_free in HealthComponent with a signal emission that the player can choose to use or not
How can i emit a signal, is it get_parent().die() for example or am i missing the point?
Because if it's what i wrote, you have to declare a die() function for every object
@@paul_musique I'm not really sure how to explain the signal system just in a UA-cam comment, but I recommend checking the Godot documentation, it explains signals really well
@@paul_musiqueYou don’t need to use a parent for signal emissions. You just need an acccessuble entity to connect to. Many godot tutorials use a “global” or “manager” script that contains their most common functions / signals which they can emit to from any script or object.
This has to be one of the most (if not the most) approachable explanation of inheritance vs. composition. Very easy, straight forward and clear. I had to learn it the hard way and for the longest time couldn't understand the advantage. I wish I had this video back then. Love it!
inheritance - "x is a..."
composition - "x has a..."
aggregation - "x uses/knows a..."
@@YammoYammamoto idk man for me these kind of explanations just confuse things more. Its such an abstract explanation to the point its hard to visualise how it would work in code.
When I develop in Godot, I often use a mixture between inheritance and composition, and oftentimes, I use resources instead of nodes for composition since it is easier to modify through an export statement.
For example, I have a slew of statemachine resources that I can plug in to my Actor class (which is basically an entity class), which makes it easier to trade behaviors depending on the entity type and whether there is currently a cutscene or battle.
I kind of got deeper into godot recently and I'm using custom resources unaware of this video's specific subject.
I find it very weird that custom resources aren't being heavily promoted by tutorials.
Need the same enemy to have different types of stats or damage, just drag and drop.
It's like secret godot magic because there's only like 3 decent videos about it.
What going on? I ctrl+F and this is the only comment talking about resources O.O
@Pulse_Skeleton Yeah Ik, weird right? You'd expect this miracle solution to be talked about more.
It's so useful for, say, making multiple unique character objects in game from the same Actor scene without having to make seperate actor-inherited scenes for each character.
@@lunaticwyrm4675 is there a way to get type hinting for resources? Can they expose code to their holder? can I set default values for them in scenes and have those values hold when I instance those scenes without having to fiddle in the editor for each one?
I've been trying to expose precise constraints from gdscript to the editor so it's easier for my team to use my modules, but I find nearly everything tedious to configure outside of a textual format (which prevents getting good adjustment/previews/feedbacks/hints in the editor).
This clicked for me. Was trying to learn this topic and you explained it so well in such a quick but well paced manner, never stop teaching, this was amazing
Composition as a design pattern I think is uniquely equipped for solving problems and making more robust (and easier to maintain) code. There aren't a lot of videos on programming patterns in Godot and seeing this is great. Talking about general/generic problem solving I think helps beginners out a lot by helping us step outside of "How to do X" to thinking about breakdown solutions to fit their own needs/program. Tutorials have their place and purpose of course, but I think Godot (programming in general to be honest) is in great need of this sort of problem solving/design thinking sort of information. Great video!
as much as I love making pretty and readable code… we have to admit it honestly doesn’t matter for 99% of godot games
Your tutorials are so good. There's plenty of beginner tutorials for Godot at this point, but we are seriously lacking in simple guides on how to architecture games. Tutorials like these are incredibly valuable and many budding game devs wont even know that they need to be looking for this kind of stuff. Please keep making tutorials!
Coming from Unity where you can throw multiple scripts on things without thinking or use multiple inheritance, this kind of helps me get my head around how Godot is 'meant' to be used! Good tutorial.
Now I see one more reason why unity games are so laggy and taking a tons of space.
@@Bloody_River scripts don't take up much space at all, it's all assets
Ye, I didn't mean scripts takes much space. I said in general. But scripts making laggy btw. So yeah, unity sks anyway.@@kurushimee
@@kurushimee they actually do. Spaghetti code leans into massive super classes bloated with a lot of functions and huge objects that aren't properly managed in the memory by the program. So, even tho they aren't automatically making your code laggy or bloated, the usage of inharitance leans into this kind of problem really easily and it gets really hard to manage the memory usage of such objects.
If you would use scriptable objects you would be golden
Excellent tutorial!! This is one of the most concise explanations of the Inheritance versus Composition concept I have seen. The fact that you separate the theory from the later example makes it all the clearer
Man you are easily the most clear and efficient teacher I've found for game dev / Godot on UA-cam. Hope to see more videos. Thanks for the help.
Loved the simplicity that you found to explain an not so simple subject with easy to follow examples. Thanks for bringing this one!!!
Bro, you need to continue this type of videos. I'm really learning from this.
This describes exactly my struggles. I’ve been trained in Object Oriented languages like C++ and Godot’s implementation is really challenging the way I think about this stuff. Thank you so much!
Easily the best godot tutorial on this entire website. It's so clear and to the point. Who knew that you could teach me how to clean up my code in 7 fucking minutes?
The first video I found on this topic was the epitome of the "Every programming tutorial" meme video, but your video made everything click in my head immediately! Thank you so much for explaining composition in a quick and easy-to-understand way!
I come back to this tutorial every now and then just as a refresher. Each time I pick up a little more of the details. Definitely worth coming back to.
Damn, just found out about your channel and you do a very good job explaining these kind of topics (classes, inheritance vs composition). The Godot community needs more content creators like you
I've been working as a software engineer for more than half a decade and this is by far the best explanation I've seen for Composition. Nice video, keep it up!
I've watched like five videos from different people about composition, and this one is, by far, the most demonstrative one about why exactly composition is better than inheritance. Many congrats and thanks and praises for such a good work of topic telling 🙏
Best video ever, and this is not just for Godot 4, this works well for Godot 3 and mainly other types of programming if you get the logic behind it. Perfectly explained and simple. Absolutely brilliant
These videos are invaluable, man. I've come back to these several times now as quick refreshers as I'm still learning everything. Truly great
really solid video, started with theory, showed a fun example, really made it concrete. clear, informative, love it.
Great video, not only displays composition trumps inheritance in a lot of cases (inheritance has it's use cases) but also ties into how the workflow in Godot is awesome with it's Nodes system.
I really like how clearly and concisely you described the two strategies and how composition can be a preferable way of organizing your code. I look forward to more videos from you!
I always love seeing how other developers perceive and approach different problems, even if we both come to the same solution. It definitely helps when you make a video that's as well presented as this one! Great work
You explained this so elegantly. I've been trying to wrap my head around HOW exactly I implement an ECS in Godot, and I finally get it. Thank you so much
I just started with Godot. This is a really great tutorial. I was just trying to reformat my code and see what other people are doing and this is exactly what I was searching for. Your videos are very valueable to me :) Keep up the good work.
did you have programer background?
I've been using Godot for a good few years now and I have never thought of this for some reason?? This was such a fun and informing video!! I'm excited to put these concepts to use.
What makes godot more challenging for Abstraction and keeping code simple, is all of the different ways you can maintain variables-
Sometimes it’s beneficial to assign a variable @ export , but there are also ways to usually do that programmatically.
Sometimes referencing a node with $ is beneficial, but it can also be avoided altogether…
Those practices aren’t normally an issue during programming in other languages (some languages do have “too many options” as far as syntax, with their own niche behaviors for each option, but godot does that on steroids).
nah im halfway in, and i already know this deserves at least ten times the views that it has just for the quality and the amount of work behind. great video!
I fell into the exact trap you gave as an example. Looking forward to refactor my game to use more composition and less inheritance!
YO this video was awesome. love the pace & effictiveness. you showed off a lot of stuff i needed to learn to start using godot properly and i thank you muchly for it :) into my obsidian vault this video goes!
this helped me alot, i've started using godot about less than a week ago, so far did not make my first game yet and this already gave me a good direction, thank you! however i noticed that when you got to this point in the video 3:29 you said "from the last video" without providing a card to click on(or a comment), as a youtuber myself i know that by time goes on it will be harder to search for the video manually, especially if you kept uploading videos, lastly i would really love to see a video talking about when and how inheritance is more preferred. thank you once again!
Good call, I've added that. Thanks a ton for the suggestion!
Just found your channel because of Brackeys' video! Great stuff, very well explained. I was getting into Godot and already used composition in project, but then things came up and I took a ~6 month 'break' and wanted a refresher, and this was perfect. I'm glad to see more people making videos on Godot that are slightly more than 'basic' level, because it was very difficult for me to find before. Everything was super beginner level tutorials where you just copy them without much explaining, but I was moving on to more complex things. I see you have some other vids that look interesting as well, so I'm going to subscribe and check them out too!
How have I not seen this before? This is the first video that made composition make sense to me. Thank you!
Hey, you did excellent explaining the difference between Inheritance and Composition. Not a lot of videos take the time to utilize simple illustrations (and color coding elements such as Attack, Health, and Hitbox). Very helpful for visual learners. You're on the right track, and I hope you keep making videos. That said, I'll be sending this video to my aspiring game-dev friends when I see them inevitably copy/paste code. Also, that sprite animation at the end is super cute!
Amazing video and nicely shown!
Really like how the code looks, clean and precise. Will definitely give it a shot when i feel i need it!
Thank you!! I was meaning to use a more component-oriented approach in my game, but I've struggled with finding out how to implement that properly. This video really helped me understand it better - the code examples were especially helpful!
Great video. As you concluded I use a combination of both.
Hey, so glad I found this channel. I love how you visualize these concepts and make it easy to understand. looking forward to see more of these videos. Keep it up!
Thanks!
Will def start using composition in my games and see how it turns out
I am surprised I was able to understand this since I am not that good at programming yet
you did a really good job in explaining the concepts in a pretty short time, good job!
Amazing vid! This was exactly what i needed. Can't wait for more vids like this!
This is a mind blowing way of explaining inheritance vs composition in just 7 minutes. Great job!
my man do you understand how hard it is to break down code theory to such an understandable and digestible format? you got a real talent for educating people.
I have to say, this is a really good and easy to understand tutorial for a really useful function
A time ago I made a similar sistem that mix both inheritance and composition, but it had the same soul, I found it so cool, now I notice that other people are dicovering and making it in many ways, it is amazing.
As someone deeply rooted in plain old Java, inheritance has always been my go-to, but this explanation of component-based makes things very simplified. I'll keep this in mind for the future, thanks.
Brackeys gang
You know this dude knows his stuff when the OG sends you to him.
Great video! I agree with others on how you described a more advanced programming technique in a very detailed, yet concise and clear way
I salute you for giving me this inside. I have learnt a lot in those 7 minutes and the wisdom will be put to use a lot. Thank you very much.
This was pretty much exactly what I was currently struggling with. And it was absolute clear and concise. Thank you so much. :)
Kudos. Moving from Unity to Godot, I had some idea that I was going to need to shift my thinking from Inheritance to Composition, and there are plenty of people online telling me what composition is and the basics around it (like the first half of this video) but very few showing it in action with examples (like the second half of this video)
Thanks for this
I still think that composition isn't better than Inheritance in big projects, it would get messy. And for the damage script he could have used an interface to do that.
Inheritance is harder at the beginning, but as the project keeps growing, it makes your life easier. Composition is the opposite.
@@b-lotus5145And you can definitely use interfaces if you use the Mono version of Godot, and if not there's a hacky solution provided by someone here on UA-cam that I used when I was using GDScript.
thanks for this man! I am using inheritance for my inventory system and now composition will greatly help while implementing enemy nodes
Wow, actually went through 10 videos about OOP, trying to find a way to fix the issue of inheritance. And you were the one to explain so clearly and neatly. Thank you a lot.
I've watched TWO videos and I'mma just say this is an extremely underrated channel. Wishing all the success to you. Thanks for the help.
Thank you for this. I keep hearing about how great composition vs inheritance is but really needed a super simple demonstration of it actually being done to really get it. Videos about the theory are great but some of us just need to see it done a couple times! Thank you!
You clearly put a lot of effort into this mini-series thing, and I must say... Fucking EXCELLENT job, man.
This is quite literally exactly what I needed to be able to attack trees (resources in general) and enemies in my game. Thank you so much for the explanation!
hoping for your channel to grow even more in the future. Thank you for this and have a nice day.
This is really really good advice. This pattern just feels right, like how the named classes, exports, nodes and scenes are meant to be used together to create an efficient and simple architecture which corresponds to programming best practices, but in Godot
Very helpful, this is the way. I've never really been a fan of Inheritance patterns for the same reasons you stated where base classes often do too much, and moving that functionality somewhere else is a huge pain. Refactors end up eating all your time. It's awesome to see good Composition patterns applied directly in Godot here to see first-hand how useful it is. Thanks for putting this together!
one of the best godot tutorials I've seen love it, very simple and easy to understand, thank you so much :)
Absolutely loved you used presentation style animations as well as gave real life examples, 10/10 video
Thank you so much for this tutorial! I only started my project and immediately got into inheritance hell when tried to change its order. Now rewriting what I have with this new technic. Your classes tutorial is useful too.
This is a really fantastic explanation of the difference between inheritance vs composition which I think a lot of videos on the topic miss. Generally they don't show the inheritance part and strictly talk about how to deal with composition, which on it's own is not that helpful. Great job.
Thank you! Finally someone who doesn't need 45 minutes on the topic only to not even show a half descent example!
Finally! Someone who understands programming enough to give a game dev tutorial 🎉
Subbed
For someone whho works with Java, I had my fair share of complaining about the abuse of inheritance and lack of real composition. You managed to explain it in a way that I can just replicate eithout sounding too technical. Thanks!
I loved your animated explanation. Simple and to the point! Thanks for this awesome video man
This video is the equivalent of an ice cold glass of water at 2 am! Thank you for the visuals at the beginning! I get hard concepts for visuals and now my brain is firing off so many ideas!!! 🎉
I came here from Brackeys and really want to thank you for the explanation! I am definetly going to use Composition in the future!
actually that was really helpful thank you very much
Thx, I'm currently switching from unity to godot, so explanations for design patterns in godot are really helpful. Great vid, had everything i needed for now
Amazing! Wish I had this video way back when, but it's also damn good to get confirmation I've learned a whole lot from trying and failing.
Great solution! I was currently implementing this approach and it's already working great. I was coming from an OOP background and when I was working with Godot for the first time, I was trying to inherit everything. Lol, it was too messy to deal with, and the inherited classes were not efficient.
I have one suggestion though: Maybe instead of using get_parent().bla_bla(), you can emit signal like emit_signal("somebody_touched_this_hitbox", Area), and take context from Area if Area is a particular extended class of Area (Maybe it's an Area of Enemy, etc.). This approach would easier to manage I think.
Edit: Yeah, exporting the Node2D and attaching it as a variable is also a better solution. You don't need to work with signals. Good job.
This is really fantastic work. You definitely changed my perspective on this and saved me from going off the deep end with inheritance as I'm learning gamedev :)
1:20 instead of inheritance of the whole scene, you can also inherit just the script part, then you don't need to worry about the base scene node. Script can also just inherit from the abstract base class, so it covers all the similarities between objects that for example: have collision
Loved the way you explained and put it into practice. This helps a lot people like me that struggles with massive teory! thank you!!
This makes my life so much easier. Thx bro, keep going!
You're a lifesaver! I had to give up on my shmup project in Godot 3 before I saw this.
Simple to understand, very thorough tutorial, Thank you !
Great video and explanation of concepts. Very sound tactics for creating maintainable and extensible code 👏
THANK YOU ive been so confused about a simple aproach to giving simple stats to my characters. thank you so much
There needs to be more content like this on Godot better coding practices and templates that can be used for any game taught in this fashion. Friggin great.
Thank you, this really gave me visual pointers as to how such a system works. I am used to build similar systems from scratch but am still not used to the visual approach in contrast to doing it solely programmatically
This is so much better than all the videos proclaiming that composition is “better” than inheritance. Like you said at the end, sometimes one is better and vice versa, and you’ll usually want to use both at the same time
Great rundown! One thing to note: you can actually make the collision shape a child of the HitboxComponent still and edit the shape as normal, so you don't need to set the entire thing up in each enemy. A small change, but something doable that could save a little time and effort. :)
I think I bought your game recently, crazy to find you doing tutorials as well
This tutorial has helped alot with my 3d dream game and simplifies both player and enemy taking damage from each other.
I still like the way unity allows multiple scripts to be added, over adding multiple scenes as a workaround, but this is seems like a good way to stay organized. Amazing explanation btw, Thanks!
Think of adding multiple nodes as adding multiple components. It's not quite the same as Unity, but helps align your thoughts.
I think making separate *scenes* is overkill. See my other comment about class_name.
Only that in some cases the number of nodes I have on a scene is ridiculously cumbersome in comparison to how it looked in Unity. Of course the functionality is the same, but from a hierarchy viewpoint and bird's eye view, Godot's scene is really messy.
Great tutorial, breaks the components down so simply. Well done
Excellent video. When I was developing my game in Unity for the first time, I made the mistake of using inheritance for everything. When I wanted to create a box that would take damage, it was all so badly thought out, that the best I could do was to inherit from "Fighter" to have the corresponding methods and references. So a box was a "Fighter", a bit ironic really. 😅
Now porting everything to Godot I will try to reformulate well all the code structure to components or as I call it (Place and run).
okay i found out how. btw thank you for making these. there arent that many tutorials that guide in coding in general instead of just specific coding structures
Very nice video, well done, well explained and useful.
However I would recommend against splitting that much, you end up getting negative returns. For example, the hitbox can itself be the health component, until you actually need to split more (for most games, you don't). Choosing where to split should be driven by real-world constraints, just like your initial impulse to move away from class-based encapsulation. Always do the absolute simplest thing!
Still, it's one of the best videos on the subject I've seen, I'll recommend it to people.
I just re watch that video over and over again ;) sucha a wonderful piece of knowledge !
i was once working on a project where i needed to build my own mini game engine , and i stumbled upon a principal named an entity component system ECS , and it was one of the most complicated and challenging topics to comprehend , let alone to practice , i was in a rabbit hole for about a month trying to get the basics of it , and it was hell , but i managed to understand it so deep i found your explanation to be simple and understandable more than i would've gotten it a while back , sadly i stopped working on that project and just directly skipped into goddot
Great video. Short, concise, and informative. Thank you!
Saw this in my Timeline and although I knew about both concepts, I still watched the full video as it was really spot on.