Using Composition to Make More Scalable Games in Godot

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 462

  • @TS-by9pg
    @TS-by9pg Рік тому +641

    This! I'm a web developer, and I was scared to start a game dev project because I didn't understand what the architecture of the Godot project should be. Some UA-cam videos recommended inheritance, but that seemed so clunky to me. This video is just what I needed. The community needs more videos like this. That focus on teaching you how to build a complex project in a right way, and not just simple step by step tutorials.

    • @NuttachaiTipprasert
      @NuttachaiTipprasert Рік тому +14

      Inheritance is always a terrible idea. It makes your codes rigid and difficult to maintain. This is why I hate UE's architecture since it relies heavily on inheritance. I like Unity's ECS and GameObject/Component paradigm and Godot's node system.

    • @TS-by9pg
      @TS-by9pg Рік тому +36

      ​@@NuttachaiTipprasert Inheritance is okay sometimes. It becomes a problem "when you only have a hammer every problem becomes a nail"

    • @DairanPL
      @DairanPL Рік тому +27

      @@nguyenjack2658 You mean gm is superior because it only allows one solution, whereas godot and unity are stupid due to allowing multiple ways of structuring your code?

    • @fantomas1770
      @fantomas1770 Рік тому +14

      @@nguyenjack2658 faster doesn't equal better. git gud

    • @fantomas1770
      @fantomas1770 Рік тому +12

      @@nguyenjack2658 ok, then go ahead and upload a video of your game that you can make in a week to display your mindset, design, and your "creative"

  • @Fupicat
    @Fupicat 11 місяців тому +124

    Just the first 5 seconds of this video are probably the best piece of advice for Godot ever: you should think of your reusable nodes as if you were extending the engine itself. This way of thinking has made working in Godot so much quicker and more fun for me!

  • @nrwl23
    @nrwl23 Рік тому +74

    Single Responsibility Principle, where everything should only do one thing well in its own specific context. Excellent explanation of how this works. Very useful, thanks.

  • @MMuraseofSandvich
    @MMuraseofSandvich Рік тому +78

    The best instructions/instructors teach you a way of thinking. A lot of programmers are trained in the OOP paradigm (myself included), so inheritance feels "natural" at first until it turns into a complicated mess.
    This makes a lot of sense to me, and it emphasizes breaking down a big project into smaller manageable pieces, like building a room-sized skyscraper in Lego.

    • @w花b
      @w花b 9 місяців тому +6

      I mean it's still OOP just a different "sub paradigm" as an alternative to inheritance

    • @ser-pzdts
      @ser-pzdts 9 місяців тому

      sounds like an ADs)

    • @SplitWasTaken
      @SplitWasTaken 9 місяців тому +14

      Composition is still OOP and your second paragraph is exactly why OOP came up as a concept. Universities just have a hard on for inheritance for some reason.

    • @MemoriesLP
      @MemoriesLP 3 місяці тому +1

      ​@@SplitWasTaken because it is a massively important concept in many projects
      Even in this video it could be useful. It seems like the skull is from the Enemy class. If a group of enemies require a different pathfinding that they all share, then they can be a sub-type of enemy that ovewrites the original pathfinding. They inherit all the other nodes, but the pathfinding one they have a new one specific to their subclasses.

  • @kiyasuihito
    @kiyasuihito Рік тому +154

    Love it. Godot has made me a firm believer in the concept of composition in software design, not just in games but also in the regular applications I help make at my job. One thing I found also to be nifty about Godot is being able to use Resources for much of your business logic. It makes it super easy to make unit tests by just making a scene with a single Node and give it the Reaources you want to test in its script... I'm geeking out. Godot is awesome.

    • @timothyn4699
      @timothyn4699 Рік тому +12

      any tips or recommendations on where/how to learn to use resources in Godot?

  • @Algardraug
    @Algardraug Рік тому +67

    This is actually beautiful. Pure art in software architecture form

  • @leagueoflanky
    @leagueoflanky 2 місяці тому +2

    im from an industrial controls background and this video made it finally click for me - the composition method is the same as function block method. you design a function block with generic inputs and outputs and some kind of logic inside. and then you can repeteadly use it throughout the logic controller, as seperate instances for many different objects. makes coding a lot easier but also makes understanding very easy, as once you learn ONE function block (or component in this case) you know how the majority of your game is operating!

  • @blurmarsh2265
    @blurmarsh2265 3 місяці тому +10

    This might've been one of the most helpful videos I've found on Godot, I'm very used to working with Java so I was thinking about nodes as if they were Java classes instead of "building blocks" Like how I've seen other Godot devs call them. The example of creating a component and then having it be a field required by another component was particularly helpful in understanding how to use these, thank you so mucH!

  • @gustavoalmeidadaribeira1740
    @gustavoalmeidadaribeira1740 Рік тому +25

    its always good seeing these kind of tutorials for godot bc its generally easy to get started but building good pratices comes a long way to organize the project and one day finish them.Good stuff.

  • @vidvad
    @vidvad Рік тому +35

    Very useful tutorial. I've been using composition for a couple of my nodes. I found it tedious to create at first but it makes creating new content later much faster and easier. I picked up a few tips from your video, thanks for sharing :)

  • @anicepineapple9067
    @anicepineapple9067 Рік тому +25

    This makes a lot of sense. It also creates a lot less spaghetti and what you might call "over building" than just inheritance.

  • @fighterwing989
    @fighterwing989 Рік тому +44

    This makes more sense to me, thank you. The issue I have with inheritance is that I'm not sure what common data a given base Object/Entity will need before I start exploring possible mechanics/variables, so I end up swip-swapping stuff around until it makes sense. The nice thing about this component approach is that you can manage the grouped data a bit easier in the scene tree.
    Lately I've been struggling with where to put custom Resources, because you can make a Resource "local to Scene" and mutate the variables away from their defaults, however, I feel like that could get out of hand quickly if I forgot which Scene changed things around.

    • @HamRL1
      @HamRL1 Рік тому

      When you modify the base component, does it change on all the nodes it is used on?

    • @fighterwing989
      @fighterwing989 Рік тому +4

      @@HamRL1 Negative. If your component is added to a parent scene as a PackedScene like how Firebelley does it here, it will be an instance of that scene, which is unique and can be changed however you like for each entity that has one. A Resource, however, when modified, will change on all nodes that have it unless "Local to Scene" is checked. So far I haven't found a good way to use Resources yet, but it's probably worth remembering for later on.

    • @Sylfa
      @Sylfa Рік тому +14

      The best way to differentiate between when to use composition and inheritance is to ask, "is it a X?"
      Like, this enemy skull in the video, "is it a healthbar?" No, it's an enemy that *has* a healthbar, the healthbar needs to be added through composition.
      "Is it a velocity?" No, it has velocity. "Is it a shadow?" No, it has it. "Is it a pathfinding algorithm?" No, composition.
      "Is it an enemy?" Yes! It can inherit from the base enemy node, all the enemies has a statemachine, so it can create that and add the initial state, the inherited enemies can override that state to add their own functionality. This is a perfectly reasonable point to have inheritance, and still focus overall on composition. Just make sure to not add something to the base class because "all enemies will *need* X," always ask "but *is* an enemy a X?" You can always add X through composition to the base enemy if all enemies will *have* an X.
      "Is it an AI?" No, it has an AI. In this video the AI component is so ubiquitous in all moving components that it's left as a function in the enemy itself; which is perfectly fine of course. But if many of them all just look for player then move to them, then you can create a node with that functionality and hook that in to reduce the number of places you need to alter if you make a change.
      Say that just moving on top of the player doesn't hurt them anymore, they need to "tackle" then it's a good thing if all HuntAndPounce enemies share their AI, allowing you to simply edit that one location to add them distance check and then pounce attack.
      Or maybe you want to add a faction like system, where there are player aligned survivors that you can rescue. Then if the logic for targeting the player is in a component you can change that one place to alter all the enemies at once. It doesn't even have to be a node on the enemy itself since it's a very tiny function. Just implement it as a static function on the base enemy object, or better yet, the AI components base class. It reduces the clutter in the enemies by having it be "var target = this.FindTarget();" instead of the chained "GetPlayer()?.GlobalPosition ?? GlobalPosition;" And now you can alter the single FindTarget when you realise having survivors of earlier expeditions could be a neat mechanic. Or you want to add a player pet. Or you want to have the tutorial spawn in guards that protect you.

    • @amegaplay3044
      @amegaplay3044 Рік тому +7

      ​@@SylfaWhile this is a reasonable approach, I can't fully agree with it. "Is it an enemy?" does not necessarily puts the object into another hierarchy. In fact, it's also another trait of this object, like hostility to somebody. If this seems strange to you, imagine you're going to add ability to your game, when a mirror character of your player is spawned as a hostile. You get problems, because your player "isn't enemy" and you can't just instantiate it as an enemy an easy way. But instead, you could just duplicate the player and give them "hostile" trait. In other words, the enmity of the object is also something it is composed of.

  • @r3digit
    @r3digit 2 місяці тому +1

    One of the tutorial channels that are actually fun to watch. I usually feel stressed while watching tutorials but this video felt relaxing

  • @seanmcgrady8688
    @seanmcgrady8688 2 місяці тому +1

    This is a great way of framing an approach to coding in Godot. I come from a web development / software development background, and I've almost always done inheritance. I found this video on my quest to code with inheritance and came to understand I was neglecting functionality of the Godot engine. Thanks for helping me understand that.

  • @Glubbydafish
    @Glubbydafish 8 місяців тому +1

    So helpful I never thought about how you can basically make your own nodes to use! Saves so much code!

  • @ZenryokuFGC
    @ZenryokuFGC Місяць тому +2

    Props for correctly calling it a hurtbox and not a hitbox

  • @dylandoamaral9881
    @dylandoamaral9881 3 місяці тому +1

    Literally the best coding tutorial I ever see, and I am not talking about only Godot nor only game development. The way you manage to use composition, which is a hard concept, is brillant.

  • @georgezimmer5622
    @georgezimmer5622 10 місяців тому +2

    This channel is goldmine. You're one of the few godot youtuber who actually know what he's doing and know how to architecture a project beyond toy projects.

  • @davizorder
    @davizorder 7 днів тому

    Bro, as a web developer, this video just blew up my mind for how to organize my first projects and to have good practices, thank you so much

  • @thetiphon
    @thetiphon 10 місяців тому +1

    I didnt even know that one should prefer composition over inheritance. It makes sense to me now. Thanks much

  • @domdru2967
    @domdru2967 6 місяців тому +1

    I've been looking through godot tutorials for a while now and they all show you how to develop a game from a single scene that has everything. All the functionality in one or few scripts. These 10 minutes gave me more than hours of tutorials before. The information I didn't know I needed.

  • @nERVEcenter117
    @nERVEcenter117 5 місяців тому +2

    This might be one of the best videos I've seen for understanding how Godot nodes can and should be organized, period. You gave several use cases and examples that demonstrate the composition of disparate simple components. I've been a functional programmer for a long time, and understand composition from a raw software engineering POV, but Godot's node hierarchy in particular was confusing me: How do I know which node should be the root for any given component, and which should be composed "properties" of that root node? You've helped me piece it together from a higher conceptual level than any "Here's what all the nodes in the engine do!" video.

  • @roundux
    @roundux Рік тому +5

    Man, please continue building courses. Your way of teaching is amazing and rare. You go through a lot of complex steps and make it easy to understand. You build real games and show how to do it. I miss courses where we are taught how to think (like this video here). Godot is for me the best engine for 2D in the market, but I couldn't learn how to build my own game yet because I don't have the strategic knowledge on how to structure a game idea (or break it into small components). But, I upgraded a lot following your course on Udemy! Thank you!

    • @FirebelleyGames
      @FirebelleyGames  Рік тому +1

      Thank you! More courses are coming (eventually haha)

  • @SkeletonBill
    @SkeletonBill 8 місяців тому +1

    As somebody so used to writing traditional OOP code with inheritance, this was difficult to wrap my head around. But it absolutely pays off, for Godot at least, this is such an easier way of creating a flexible and scalable project.
    Another great thing about making your components so granular and abstracted is that it makes them easy to reuse in later projects. Your health component for example, that could easily fit into pretty much any game you can imagine, in many different ways. You write it once and you're done.

  • @FalconFetus8
    @FalconFetus8 Рік тому +19

    Thank you for editing your video down! So many other tutorial videos are unedited, full of "umms", "ahhs", and long pauses that make it a chore to get information out of. This video was quick, to the point, and well-presented.

  • @Road_to_Dawn
    @Road_to_Dawn 2 місяці тому

    This blew my mind. I just started learning Godot a few weeks ago, and this is exactly what I need to start building toward. I’m wanting to build a game that has a lot of different enemies with some variations on each kind, as well as a lot of weapons for the player that all act differently. Thank you for these ideas on how to do that!

  • @ShiloBuff
    @ShiloBuff Рік тому +6

    Wow. These are the concepts I want to see more of for game development. It's a slightly older video, but it's still very relevant and important to using a proper scalable system. I would absolutely love to see more content like this.

  • @BaddyPlays
    @BaddyPlays 2 місяці тому

    I have literally started Godot a few days and just abt to finish a very simple platform practice game. This video is awesome and came at the most opportune moment.

  • @basedjustice
    @basedjustice 2 місяці тому

    needed this video today. was getting way over my head trying to figure out how to get things modular and nice with interfaces and whatnot. this makes so much more sense. and thanks for using c#

  • @renzs18
    @renzs18 Рік тому +13

    I was used to inheritance and it always brings me to a block when I have to make it a little different from its usual behavior. Looking at your video feels like this is a solution for my game so I have to save this video and keep watching this until this sticks to my mind.
    Although it is a little frustrating to start again from the start using composition but I think its worth it in the long run.

  • @CaptainCarrotzz
    @CaptainCarrotzz Рік тому +2

    I always knew that this concept existed but it never really clicked until now. Going to have to change the way I conceptualize the architecture of my games to include this framework. Thanks!

  • @JigaWhat
    @JigaWhat Рік тому +5

    This is so well put together. Just spewing pure gold constantly, no time wasted. Well done sir

  • @troidepanhseden4532
    @troidepanhseden4532 Рік тому +10

    This is a very specific example with great explanation. Thanks a lot.

  • @CassyCodes
    @CassyCodes 6 місяців тому

    Thank you! I’m just getting started with game dev. Following tutorials doesn’t help me figure out how to actually structure a game so this was incredibly insightful

  • @rmt3589
    @rmt3589 10 місяців тому +4

    This is very similar to my thought process with my game engine. Make games, then turn them into components so every future game is easier to make. It'll be very, very, very slow at first, but will exponentially speed up.
    I'm gonna play around with godot a bit this year, and possibly publish one or two games with it. Need to finish learning a couple skills from Unity, then I can (probably) delete it forever. When I get to Godot, this will help me bridge my knowledge from designing my own engine.
    Thank you so much!

  • @MCNeko6554
    @MCNeko6554 Рік тому +3

    Great explanation of composition. I was only familiar with inheritance from my studies since none of my programming classes mentioned composition at all. However, I've been seeing a lot of composition-related Godot videos recently and I thought that they were essentially the same thing. It's clear now that inheritance is really only top-down while composition is bottom-up. Thank you for the overview!

  • @grass324
    @grass324 8 місяців тому +1

    ngl this is a way better explanation of composition in godot just an extremely simple and straight-forward explanation and shows how powerful composition is.

  • @chanlsdon6176
    @chanlsdon6176 9 місяців тому

    Very Impressive Tutorial! I was completely lost on how to manage node structures, then I saw this. All my doubts were then cleared in this 10 minutes video.

  • @MakiNoAtorie
    @MakiNoAtorie Рік тому +1

    This is so useful, a ton of Godot beginner tutorials tackle programing as a hierarchy project instead of a component one. I understand its because is easier to understand but it'll only hurt in the long run.

  • @NonUnknownDev
    @NonUnknownDev Рік тому +12

    Dude you rock!!! what a nice tutorial, I mean I know about composition, but you have opened my mind a lot for this!!!

  • @KaevYT
    @KaevYT Рік тому +2

    I'm new to Godot. Today i wrote a little node called "MovementValidator", which either returns a bool that shows if my player can move to the next tile. I actually made it as an own Node because i thought it might be nice if i could reuse it for different kind of units aswell. Wasn't sure how i felt about it. This tutorial has shown that i was on the right track all along! :)

  • @Dailyfiver
    @Dailyfiver Місяць тому

    This is absolutely life changing workflow

  • @rafaelberro5056
    @rafaelberro5056 Рік тому +3

    This is awesome! Changed the way I'm structuring my whole project that I recently started and probably the future projects as well, thank you so much!

    • @rafaelberro5056
      @rafaelberro5056 Рік тому

      You've also made me change from GDScript to C#. 👀

  • @Maffia7
    @Maffia7 Місяць тому

    Thank you for explaining this to me with a fitting example. I was getting stuck in a inheritance with composition way of coding and it just didn't feel right, but now I know how I can just split logic into new nodes instead of having an inheritance tree that is too difficult to manage when adding more differences between scenes. Regarding the targeting, technically you could add an argument to it that sets the IFF and therefor enemies always target players and npcs always target enemies... however I think the reason why it's sometimes good to write duplicate code is that you might save a lot of time on making something generic, when you never need it again and you are likely the game designer, you know what you need a lot of and what not.

  • @Riotality
    @Riotality 2 місяці тому

    Just started my godot journey and came across this video. One of the most informative videos out there on how to structure your scenes / nodes. Much appreciated for this and glad I found it early :D

  • @richardwolfe2089
    @richardwolfe2089 Рік тому +9

    Thank you for this. This is a huge eye opener for me.
    Having purchased your Udemy course it's been a treat to see how a design goes from monolithic while testing to composition based and modular.
    I recently came across using custom resources in Godot 4, and they seem very similar in their use cases, just with storing data and not necessarily logic. I am struggling though because I find the node composition way easier to wrap my head around.
    I also ran into a bit of a footgun recently when I tried to make an inventory system and items out of resources. It all worked fine until I realized that resources are not unique....so updating one items quantity affected all other duplicate items in the inventory.
    Anyway, thank you! Sorry for the ramble!

    • @FirebelleyGames
      @FirebelleyGames  Рік тому +4

      It's useful to know that every resource will be default shared by reference, including resources that are assigned in the editor. You can get around this by duplicating the resource before making your changes!

    • @101touchapps
      @101touchapps Рік тому

      oh wait theres a udemy course? 😮 faak i want this guy to teach me godot 😢 (pardon my french)

  • @CatMeowMeow
    @CatMeowMeow Рік тому +1

    Thank you! I've seen a few videos explaining composition and this is the one that made it all click for me. Showing an actual game ready non-hypothetical result really helped. All the other explainers I've seen confused me because they just used example projects that where small scale

  • @TheMikeMassengale
    @TheMikeMassengale 5 місяців тому

    This was very well explained. I now find myself glad I got into this when I did, as this is how I have always thought of code, and to find that it isn't how it normally is, makes me see why I always had these hang ups in understanding before.

  • @ЛевАронов
    @ЛевАронов 5 місяців тому

    this is actually so wise and beautiful... i'm only starting to use godot but I hope one day I'll be good enough to create a somewhat big of a game that would include a lot of stuff that I watch on youtube

  • @juansnyders7323
    @juansnyders7323 Рік тому +2

    This is one of those videos that have just such a sheer amount of volume in terms of knowledge and useful information that I flabbergastedly watch this in the hopes that I can absorb at least a fraction of it

  • @javgroman
    @javgroman Рік тому +2

    Useful summary, man - thank you - the state machine commenting was also very insightful. Kudos!

  • @siderisanon7860
    @siderisanon7860 Рік тому +2

    A very nice breakdown with an explanation that really made sense to me. Thank you. I am just learning Godot and thinking of it as composition this way helps make the patterns of it seem more logical to me.
    Your lecturing style is also quite good, unlike some video makers who sound like they're making it up as they go along. You clearly have at least an outline or even a full script.

  • @jkf16m96
    @jkf16m96 Рік тому +2

    amazing video, this is exactly the kind of design i was looking for in my game.
    I just didn't grasp exactly how to make this kind of composition to also use godot features.
    With this I can make my game, you have my like and subscription

  • @elhefe83
    @elhefe83 7 місяців тому

    Dude, you basically answered all of my questions on composition in about 10 minutes. Mind: blown.

  • @khzzzzzzzz
    @khzzzzzzzz 11 місяців тому

    For anyone who loves code, but is new in godot or gamedev, this video is just art. You open my mind, thx bro..

  • @GDScriptDude
    @GDScriptDude 10 місяців тому

    Very nice explanation. I didn't think about adding nodes to a scene being composition. We can also create a script with a class_name in Godot to use where we only need to reuse a chunk of code. I ended up doing this after searching and watching your video.

  • @contentatogames
    @contentatogames Місяць тому

    Just came across my feed as I start a new project. Awesome and perfect. Thanks!

  • @JackKell100
    @JackKell100 Рік тому +3

    This video was extremely useful and this type of game architecture content is worth its weight in gold. Keep it up!

  • @guyduincognito6416
    @guyduincognito6416 5 місяців тому

    I spent alot of time learning patterns, but this video explained everything i needed. Thanks

  • @andrewgreenhouse
    @andrewgreenhouse 6 місяців тому +14

    The thing is, how do I actually build these as a Godot beginner? I understand the pattern and I actually think it's very good, but I wouldn't know how to create components from scratch. Like, are they all Node2D elements? Also I don't wanna copy the code from the video because I actually want to understand what it does. Thank you!

    • @c4r4dd1ct6
      @c4r4dd1ct6 4 місяці тому

      I’m rather new to this as well but it seems that since the task of everything is so specific there isn’t really a node for it beyond Node2D/Node3D, so most of these small nodes are just those. In a way I guess it’s like being able to attach multiple scripts to a single object in Unity or other similar engines with a script to manage the health, the movement and input, the combat ability, etc. Of course it isn’t all those base Nodes (the hurtbox was made with Area2D/3D as a base because collision is complex enough for Godot to have specific built-in functionality for it), so I’d say watch out for that. I’d appreciate the thoughts of someone with more experience, though, I’ve just scratched the surface with Godot and made basic projects in Unity. Hope this helps!

  • @donatkamary8137
    @donatkamary8137 Рік тому +1

    Merci beaucoup. Je n'avais pas vu le développement de jeu sous Godot de cette manière. Thank you 🙏

  • @ptkstefano
    @ptkstefano Рік тому +1

    I started your course yesterday and found your channel right now by accident. You're a great teacher and I'm glad to be your pupil :)

  • @tomsterbg8130
    @tomsterbg8130 6 місяців тому +2

    I'm not even that good at Godot and kinda gave up, but I've known Roblox for years and now that I understand packages I am going to attempt to use composition through that.
    It's even better than Godot because packages have the option to auto update or not, they can be shared, they have version control.
    This is so beautiful, thank you for sharing! I'm sure that utilizing composition in ANY engine will make your game at least 2x more scalable.

    • @tomsterbg8130
      @tomsterbg8130 4 місяці тому +1

      Coming back to this, I've currently decided to never go back to Roblox again and stick to Godot for as long as possible. At least 10 years because I'd benefit more if I find ways to improve the engine myself instead of going for the new hype or industry standard.
      Currently I have a template project meant exactly for this - making assets and components in one place in order to make development faster by just prototyping in that template or copying it to a separate project.

  • @Lion4de
    @Lion4de 9 місяців тому

    This was awesome! I’ve seen a lot of people talk about composition, but there is always some strange tethering. This did a great job of showing how to take composition to its natural conclusion.

  • @11nephilim
    @11nephilim 6 місяців тому

    I'm still completely new to both coding/Godot but I have a feeling I'll be coming back to this tutorial when I get more confident!

  • @mmmat8265
    @mmmat8265 4 місяці тому

    Just what i needed!
    - Mario
    I recently (last week) started my game dev learning journey, and i already have spaghetti brain, and as a result, spaghetti code. Now Godot is making more sense to me, and perhaps i can fix up my spaghetti code now. Thanks youtube man

  • @TomCrowKid
    @TomCrowKid 2 місяці тому +1

    Well explained, great examples, super clean implementations. Everything is just perfect.

  • @rhysj125
    @rhysj125 Рік тому +2

    Great explanation, such a clean way to create these bits of functionality. Looking forward to giving it a go!

  • @smolblockboi
    @smolblockboi Рік тому +2

    Will definitely be referring back to this as I delve into Godot 4. Always struggled with larger projects ballooning. Many thanks for the insight!

  • @WeirdDuck781
    @WeirdDuck781 Рік тому +3

    Worked with ECS, but I do enjoy the simplistic way you can achieve composition in Godot. Unity is sort of the same thing with Mono behaviors apart from not forcing you into one component per node. Very neat and concise video!

  • @lightfeather7948
    @lightfeather7948 5 місяців тому

    honestly, this is really smart I'm suprised I didn't come up with that alone

  • @ipdramon2177
    @ipdramon2177 Рік тому +8

    Statemachines are exactly where I use modularity :D
    I implemented my own state machine and have edges with conditions like "EndReached" within my AnimationTree that I can easily reuse.
    With inherited scenes I was able to get the best of both worlds where I use the scenes more like a template. Works well for my player characters so I have to check how it will work with my enemies :)

  • @utfigyii5987
    @utfigyii5987 Рік тому +1

    I am trying to learn how to architect my projects better. This is a great help!

  • @drvortex
    @drvortex 10 місяців тому

    Thank you so much. THIS is the glue. Every tutorial out there covers a small miscelaneous detail and totally gloss over the important stuff. This is the way the engine was intended to be used, and I needed an explanation like this to understand it.

    • @vast634
      @vast634 6 місяців тому +1

      In general tutorials mostly focus on a specific mechanic in a simple toy environment. Overall architectural design is not that often brought up. (That includes how to handle a large amount of assets, source control, naming conventions, scene management, and things like that).

    • @drvortex
      @drvortex 6 місяців тому

      @@vast634 thank you for taking the time and effort to address it.

  • @fenice319
    @fenice319 6 місяців тому

    this is great, I have no idea how to even begin to integrate this myself but at least it gave me a clear idea of a really good way to organise whatever I'm trying to do

  • @PaulSpades
    @PaulSpades Рік тому +3

    I think Godot itself is structured a bit differently:
    - container nodes that are bags of stuff and that's where you reference everything;
    - 'functionality' nodes that work with the built-in systems but are mostly data.
    - core systems logic that manipulates the functional nodes
    It sort of looks like your structure, but your container nodes also contain your game systems, I think.
    I guess the game systems (scripts) living inside a container node is the only way to do it, so the shallower the container structure the more modular everything becomes.

  • @ItsMeChillTyme
    @ItsMeChillTyme Рік тому +24

    This is a sigh of relief. I followed a tutorial and as a web dev it was just frustrating me to see it all turn into spaghetti. I asked people around and seems like since most people just wanna get a game together, there's little concern over the code itself besides it just doing what it should, especially for lightweight games. Management was going to be hell for me that way. I am glad that I found this.

  • @derpydino17
    @derpydino17 3 місяці тому

    Wish I found this video before starting my game. Awesome tutorial.

  • @AlexJWayne
    @AlexJWayne 10 місяців тому

    Stumbled on this and it really made Godot click for me, finally. Thank you so much for this.

  • @rhyspuddephatt
    @rhyspuddephatt Рік тому +1

    Interfaces are also a good shout for generalized modular components, your health component will sign the interface contract then you can make a different health component that works completely differently but so long as that component signs the same contract the rest of your code will treat them the same

  • @BazSupport
    @BazSupport 9 місяців тому

    Thanks for this, I was struggling because I too seem to need many specific state machines, so your advice at the end was really helpful

  • @OctagonalSquare
    @OctagonalSquare Рік тому +1

    This just makes sense to my programmer brain. It’s like object oriented programming but for nodes.

  • @elliottducharme7004
    @elliottducharme7004 6 місяців тому

    This video is making a fine addition to my collection of Godot tutorials. So glad I found this channel. Really looking forward to doing projects with Godot!!

  • @michaelpascale6570
    @michaelpascale6570 Рік тому +15

    This is a great explanation and demo of this concept. I am not totally convinced that inheritance wouldn't be a comparably viable a solution, especially for the claim made at 3:17. A handful of of derived classes off of the base gun and bullet classes with the use of configurations and maybe techniques like dependency injection could get you comparably as far in a comparably scalable manner.
    Anyways, I am sure you've done what's best for your game. With how Godot is structured, you can never fully get away from composition (not that you even should!)

    • @FirebelleyGames
      @FirebelleyGames  Рік тому +19

      Absolutely, I wouldn't claim that inheritance isn't viable (apologies if it came across that way) and there are ways to mitigate the risks that come with inheritance. And there are scenarios in which inheritance is clearly preferable to composition.
      The beauty of programming is that there are multiple viable pathways to the same outcome, and we can choose a strategy that works best for our projects!

    • @pythonxz
      @pythonxz Рік тому +6

      @@FirebelleyGames Interfaces are also a great option to get polymorphism without the coupling that comes with inheritance.

    • @spindash64
      @spindash64 Рік тому +1

      If possible, it would seem to me that the best solution would be a mix of inheritance and composition: using inheritance specifically for the _minimum common features_ of certain objects. For example, both types of guns appear to spawn new bullet entities, even if the behaviors of those entities are entirely different. and those spawned bullets will likely all want to use a hitbox to inflict damage on a target
      Of course, I'm not designing the game, so I can't say with absolute certainty what things will or won't be held in common. But putting the baseline commonalities in a class can still potentially save you some time

    • @trickster721
      @trickster721 Рік тому

      Yeah, ridiculous claims like "inheritance stops me from making a gun that shoots worms" only deepen my belief that all the Godot devs preaching this "inheritance is bad" mantra are just bad at inheritance. If inheritance is so bad, then why does Godot use it for all the built-in nodes?

    • @PamellaCardoso-pp5tr
      @PamellaCardoso-pp5tr Рік тому +1

      the thing is that, dependency injection in some sense is just a way to mimick composition using inheritance.

  • @pibemacaco
    @pibemacaco Рік тому

    This video has helped me a lot! I've been struggling with inheritance in my game for a while, having to create tons of subclasses to achieve my purposes, but now it's much easier. Thank you!

  • @Belhenix
    @Belhenix 4 місяці тому

    Hello, here from the future. I love the explanation from this video because we can see things from 2 different perspectives:
    From one perspective we see the video topic, nodes and modularity making games a lot more scalable. Not only that, but you just trivialized making a new enemy from scratch by adding components and making it extremely easy, while taking the traditional route would make it easy for 1 time but a real chore for a bunch of times. At 8:08 we can see the different scripts, blue ones being pure composition and white ones being custom ones, allowing the creation of an enemy with minimal code. It really is only ironing out the details or defining specific behavior, as said when commentating on the state machines.
    From another perspective, as an object oriented programmer, this is the best example of classes vs objects: Having the structure in mind to define an enemy is one abstract class, albeit an incomplete one being made whole by "fake" interfaces in the form of node components. When constructing the whole scene with the base node we are "instantiating" the class into a defined structure, adding as many components as required and changing the values of said components as desired (HP, speed, tracking, etc.) In the end we are left with a specific entity to do a specific task, and even if it's duplicated it will be its own entity amongst others. In other words, its own object.
    Love the video, already liked and subscribed.

  • @yvanvan3729
    @yvanvan3729 Рік тому +3

    Another amazing video !
    Great explanation and example of how to use composition.

  • @ewee-st1de
    @ewee-st1de 4 місяці тому +1

    I have been following a tutorial right now and he did show like a hitbox and hurbox scene that can be used multiple times but he kept the hp as just a basic player and enemy attribute.
    I think its a good idea to keep everything separate like you did, having this whole health component that only changes the health value with the associated signals does feel like an official component like the Timer or something.

  • @DodgySmalls
    @DodgySmalls Рік тому +19

    One detail of Godot that is highly relevant in this context is the explicit separation of scenes and scripts. When learning Godot, I was used to other engines, where the engine presents you with the option to attach scene components to a script at any time. It took me a few hours of confusion to understand that in Godot it's normal (even expected) to use scenes for typing rather than scripts (i.e. in-code types).
    Also, on the conversation of composition over inheritance, I think it's best said "(consider) composition before inheritance". Inheritance is still a powerful tool, it's just one that's less flexible (especially in the face of changing requirements) and therefore easier to misuse. For example it's great to extend base-class components to provide niche functionality. You could for example design a phased-health-component for bosses which allows you to retain an entity but use multiple healthbars and fire other triggers (while retaining the base class's existing death trigger).

    • @RoadsideCookie
      @RoadsideCookie Рік тому +2

      I know I'm replying to an old comment, but there's an easy line to draw between composition and inheritance.
      If your concept can work without the other thing, it's probably composed.
      On the other hand, if it can't work without the other thing, then it's probably inherited.
      However, there are other methods that are sometimes better than inheritance still, for example dependency injection.

  • @oskarkunik5154
    @oskarkunik5154 Рік тому +1

    I bought your Udemy course after watching this. Thank you for sharing your approach, it's been really helpful.

  • @theyellowarchitect4504
    @theyellowarchitect4504 Рік тому +1

    Great video. Components accepting components (hurtbox taking health ftw) is good design.

  • @nathangarcez3926
    @nathangarcez3926 Місяць тому +1

    Please, create some tutorials about it!
    This video was a shock for me.

  • @guilhermecosta6731
    @guilhermecosta6731 Рік тому +2

    Icredible video! I use godot for a time and always struggled to understand that logic. Thanks A LOT, (and happy christmas)

  • @Ducky39101
    @Ducky39101 6 місяців тому +1

    I have been looking for something just like this! Thank you so much!

  • @tonyanimations5377
    @tonyanimations5377 Рік тому +2

    Tip: If you want to edit a specific behavior of one of your generic scene, in a way that's is not really great to use exported variables as options you can do the following:
    Let say with your HurtBox node you can do a signal that emit to ask the permission for taking damage and pass the variables in that signal.
    You connect this signal to your root node and add conditions, and if all the conditions are met you call the validate_damage function of your HurtBox node, like that you can even modify the damage etc...
    Just an idea, tell me if that's great or not ;D

  • @djbolodocaco775
    @djbolodocaco775 Рік тому +1

    finally i understood this, itll be hard to implement when starting out but this is amazing
    Thanks for this masterpiece!

  • @grantforrest6538
    @grantforrest6538 5 місяців тому

    I've been a developer for over a decade and have always taken code structure seriously. When I started out I made a bunch of games, but the more I got experience with other parts of the field, the less I felt I understood how to return to gamedev. Tutorial code always seemed unscalable. I just couldn't figure out how to translate good practices I've learned elsewhere to my projects. I was just working on trying to implement conveyor belts in a new game and trying to avoid tight coupling and having to implement "apply velocity per frame" behavior in every movable node's script... I knew this couldn't be right, so I googled "godot composition" and here I am.
    This video is really energizing, because it's one of the first I've found where the code shown looks production-quality and enjoyable to work with. I've been bouncing off gamedev for years because I cannot stay motivated when code feels messy. Your compositional style here possibly isn't unique or even that rare, but I'm grateful you took the time to give such a clear example as it's given me some hope I can finally 'click' with gamedev again.
    Purchased your latest course on udemy. Cheers!

  • @zZMazeZz
    @zZMazeZz Рік тому

    This is great. I would LOVE to see how your different guns are built out. Thanks so much !

  • @kennethmontgomery1621
    @kennethmontgomery1621 Рік тому +1

    Very clear and useful example of composition 🤯

  • @FearsumFoe
    @FearsumFoe 10 місяців тому

    First video I've seen by you and honestly completely rewrote how I think about modular design. Totally subscribing.