You're not using Godot to its potential

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
here's a quick demo I made we have a player whose only means of interacting with the world is pushing and slamming into things this switch can be switched and the crit can be broken how would you make something similar while keeping it extensible okay well since everything is snapped to the grid let's have them inherit grid object rocks and crates can be pushed around so inherit pushable grid object the player is obviously its own thing switches can be interacted with so inherit interactable grid object yeah oh but the crate is also technically interactable so inherit pushable interactable gr object no no how about making all great objects pushable and enabling it only for those we need but then these guys have a bunch of code they're not even using at all and if we did this for every misalignment like this we'd end up with a lot of objects with a lot of useless parameters and methods H what to do of course this is a small and simple example but this sort of problem often pops up with objectoriented programming often times your codee's functionality doesn't neatly organize itself into a tree likee structure you're going to have exceptions the more you try to organize your classes like this the more you'll end up having to introduce vague and obscure parent classes that don't really contribute anything to your app imagine you're in a firstperson shooter game and you got this cool new gun that shoots piercing bullets now what if you wanted it to shoot piercing fire bullets instead object-oriented programming would tell you that's not possible because it's not part of this other family have guns that specifically shoot fire bullets and as a Dev this kind of sucks one popular solution to this is entity component systems with ecss functionality is extended not inherited in our FPS analogy components are like mods you attach to upgrade your gun add the fire bullets mod to your piercing gun and BIM Bam Boom piercing fire bullets want your gun to steal enemy Health just add the leech mod maybe there could be a Synergy there where your enemies burn and you slowly absorb their health you get my point it's super flexible and what do you know the second most popular game engine on GitHub uses entity component systems one downside though is that it can be repetitive and tedious sometimes ideally we want a mixture of both you know what is g go do God whatever but Kent how is Godot an ECS it's clearly objectoriented well in Godot we have nodes nodes can have parent child relationships and nodes can represent anything even functionality so how about we make a script that makes its parent pushable and slap that as a child of anything we want to be pushable in short that's how I made that demo I have a pushable component I can add as a child to any grid object node and it's going to handle all the pushing logic same thing for the interactable [Music] component now if you want crat to be both pushable and intera rable we just add both and the neat thing about using nodes as components is you can dynamically add or remove functionality for example we could dynamically enable or disable the interactable component on that enemy in full Baba is you Style again Game Dev is a balancing act you don't want to go too far with this for example we wouldn't make a grid component since all objects will need it and it's just going to make it redundant and tedious for ourselves inheritance is better suited in this case now you may be asking okay so nose can have components which are nose in and of themselves so how do you make references to those components how do you even detect if a node has a certain component well there's a few way to do this first is to use export variables for in editor node references it's easy to implement and it's clear what the dependencies are second is to use get node or get node or no but it does mean you can't really have components that aren't direct children at least not without looping and third using metadata which is what I did when a component enters a tree it registers itself and its owner's metadata next if you want to get that component we can just call get meta or as meta to check if it exists so yeah inheritance can often be limiting try using components they simplify things keep everything flexible and they're pretty intuitive as well I hope you learn something see you next time [Music] la
Info
Channel: Tienne_k
Views: 65,459
Rating: undefined out of 5
Keywords:
Id: ldxDJpRPCMI
Channel Id: undefined
Length: 6min 12sec (372 seconds)
Published: Thu Mar 28 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.