Super easy to understand Class tutorial. Godot is really showing itself to be a very powerful engine, being able to create your own Nodes with one line is a powerful tool for developers to pull into any project and reuse their code.
this video is very well explained. I knew how to more or less use classes in c++ but when I saw a couple tutorials of them in godot I couldn't figure out how they worked. thanks to you i think I get it now. your explanation was very clear, subscribed.
Your tutorials are hands down the best out there! I have not been able to watch all your videos, but I'm working my way through your videos one by one. If you have not made it yet, I would love a video going in depth on Planes, Normals, dot-function, and all that jazz. With my ADHD, I'm having a really hard time grasping how this works, and I find myself debugging for hours every time I have to calculate distance, angles, and stuff like that. Anyways, thanks for the great videos!
this tutorial is really clear and easy to understand. This makes creating classes and using classes to make components very easy to understand. Thank you!
So amazing that I was literally struggling with this all afternoon, I had like 4 videos up showing how to do it but not as well explained as you. You answered questions I had about this. I'm trying to use it for NPCs (if you'd ever need a topic for a video, please show us how you would go about that :D) Thank you for your video :)
at 6:14 you went ahead and made the collision shape unique. out of curiosity. Can't we set the collision shape in the base class to "local to scene" via Shape -> Resource -> Local To Scene?
I always get confused on when to use composition or classes in new projects. Could you consider making a video on when to use one over the other (in a generalized manner, or course)? Great tutorial, btw. Although I'm already used to OOP, Godot's python-like language still gets me confused sometimes
I just have a question, why didn't you place the code from _set_heatlth into the "take damage" function? When you do health = new_value, wouldn't the function _set_health be called again?
I feel like I'm using custom resources wrong or not getting the most out of them. In the game I'm working on, I intended to use them to pass attack data from the attacker to the target, however, I had to resort to using dictionaries instead. I'd really like to see some practical application of custom resources that shows the best use cases and their advantages.
What would You say would be better for a game that spawns waves of enemies like a Tower Defense? Using Composition for the Enemy by splitting the health, take damage components or by using an EnemyBase class which will have all of those things. Still quite new to all of this and have been trying out things. If I for example add armor and maybe special abilities to the spawned monsters that would have to be used in the script for the exact monster I am going for but using these two things I mentioned should take care of the heavy lifting? Still trying to see how things work.
So for the enemies, I'd definitely create an Enemy class to handle all the common functions (like ai, movement, etc.) You could then export properties for things like a Health Component, Stats Component, etc. (all different classes), and these could handle the more composition-oriented logic. Hope this helps!
Every instance of a class will have the same properties, so to give a class a "unique" property, you either need to inherit the base class (and add new properties), or add metadata
so it's just kinda useless...what's point if i can just save a node.tscn with a script on it and attach it to other scenes that needs? cause if there's no difference then classes have no reason to exist.
No there’s a multitude of uses for classes, not having to rewrite code is the biggest. If I have ten enemies they can all have the same health. Why create ten scenes with the same script lines written. When code can be reduced it should be. Example, you have a script where you want enemies to spawn every time an enemy dies - you can use a class with a condition statement stating if enemy_dies(): PathSpawn Then no matter the enemy type that died when you kill one it respawns. Then you didn’t have to write the spawn script on ten enemy types. If you plan on having no variety or spaghetti code sure you can ignore classes. If you want to speed up production, have cleaner, more efficient code then use classes.
@@H3_remix I have no idea what do you mean by reduced code? How do classes reduce code if it's just another script you instance? Its literally just a script saved as .tscn....same thing as writing a script and attaching it where you need it
@@Ceisri you’re missing the fundamental point of classes. If you have ten enemies and they all have 100 health, why would you need to write ten scripts for their health, movement or spawn position. You’re writing much less code because instead od creating ten variables in ten scripts you have one script with one variable. Health. You could then extrapolate it further and add their movement. You can then have their specific mechanics only in their script, but because they’ve inherited the enemy class they don’t need the health variable in each one. Thus you’ve reduced your lines by a minimum of ten in this example. Because your enemy class already has a health variable, or spawn variable set you can write it once and then set each enemy to be a part of the class. I’m not sure where we have lost each other here. The difference being classes are declarative while nodes and scenes are imperative. Declarative meaning it doesn’t need to define its control flow. Imperative meaning it’s described step by step in detail. Are scripts/scenes similar to classes, yes, but they are not the same. As dor the node with a script attached you’ve created an imperative code. Rather than being declarative as in classes. There is extensive documentation on the godot site about classes and how they function if you have further confusion.
@@H3_remix Multiple instances of the enemy.tscn scene will share the same code file. Then if we export the health variable it can be made unique for each enemy directly in the editor. No need for classes or additional lines of code. @Queble this is a great tutorial, but I personally would really enjoy some more real-world examples of how classes are better than just instancing scenes!
So classes and inheritance are essentially the same thing. Let's say you have a Entity class with and entity name, then 2 sub classes: Player and Enemy. These 2 subclasses also would have an entity name, so they would both inherit from the entity class. This is called inheritance, because we have two subclasses inheriting from the parent class AKA entity. What you might be talking about, and something I would suggest looking into, is using a component system rather than inheritance
This tutorial was much easier to understand on the specifics without going too far off subject. Keep up the good work.
For me as a beginner, that was the best explanation for class I watched. Nice job!
Thank you! Very confused about classes before this but now I understand them. ❤
Awesome, glad I could help!
Super easy to understand Class tutorial. Godot is really showing itself to be a very powerful engine, being able to create your own Nodes with one line is a powerful tool for developers to pull into any project and reuse their code.
this video is very well explained. I knew how to more or less use classes in c++ but when I saw a couple tutorials of them in godot I couldn't figure out how they worked. thanks to you i think I get it now. your explanation was very clear, subscribed.
This is just a simple and straightforward way of explaining classes and inheritance!
Awesome job truly! This makes it clear for almost anyone!
Your tutorials are hands down the best out there!
I have not been able to watch all your videos, but I'm working my way through your videos one by one.
If you have not made it yet, I would love a video going in depth on Planes, Normals, dot-function, and all that jazz. With my ADHD, I'm having a really hard time grasping how this works, and I find myself debugging for hours every time I have to calculate distance, angles, and stuff like that.
Anyways, thanks for the great videos!
this tutorial is really clear and easy to understand. This makes creating classes and using classes to make components very easy to understand. Thank you!
A video on building different custom resources would be awesome!
I can confirm. This would be undoubtedly awesome. Very necessary.
Thank you for this tutorial. I've learnt OOP in university but changing on my own to a Godot proyect is pretty confusing. Keep up the good work!
This tutorial was very helpful, thanks!
So amazing that I was literally struggling with this all afternoon, I had like 4 videos up showing how to do it but not as well explained as you. You answered questions I had about this. I'm trying to use it for NPCs (if you'd ever need a topic for a video, please show us how you would go about that :D) Thank you for your video :)
Good job,I want to see a video about how to do trade-off between inherit and composition in Godot.
yes please do the resource tutorial, just as you described here 7:05! thanks! great job.
I've actually just posted it!
Checkout my most recent video :)
Thank you soo much buddy this video was very good
TYSM! Keep up the good work!
we crave another custom resources video :)
We do. We crave it!
This was amazing. Thanks a lot
nice video thanks a lot!!
at 6:14 you went ahead and made the collision shape unique.
out of curiosity. Can't we set the collision shape in the base class to "local to scene" via Shape -> Resource -> Local To Scene?
Awesome tutorial!
I always get confused on when to use composition or classes in new projects. Could you consider making a video on when to use one over the other (in a generalized manner, or course)?
Great tutorial, btw. Although I'm already used to OOP, Godot's python-like language still gets me confused sometimes
I'll add that idea to the list! :)
Use inheritance only when composition is logically impossible. In all other cases prefer composition.
And don't inherit deeper than two levels.
I just have a question, why didn't you place the code from _set_heatlth into the "take damage" function? When you do health = new_value, wouldn't the function _set_health be called again?
resources tutorial please, thanks for this Tutorial
Very well done 👍
I feel like I'm using custom resources wrong or not getting the most out of them. In the game I'm working on, I intended to use them to pass attack data from the attacker to the target, however, I had to resort to using dictionaries instead. I'd really like to see some practical application of custom resources that shows the best use cases and their advantages.
Planning on extending this video with a custom resource attack system:)
What would You say would be better for a game that spawns waves of enemies like a Tower Defense? Using Composition for the Enemy by splitting the health, take damage components or by using an EnemyBase class which will have all of those things. Still quite new to all of this and have been trying out things. If I for example add armor and maybe special abilities to the spawned monsters that would have to be used in the script for the exact monster I am going for but using these two things I mentioned should take care of the heavy lifting?
Still trying to see how things work.
So for the enemies, I'd definitely create an Enemy class to handle all the common functions (like ai, movement, etc.)
You could then export properties for things like a Health Component, Stats Component, etc. (all different classes), and these could handle the more composition-oriented logic.
Hope this helps!
please explain inner class omg bro no one on this platform is explaining this one concept
I figured out octrees before figuring out what a class meant☠️
How do you give an instance of a class its own unique variable?
Every instance of a class will have the same properties, so to give a class a "unique" property, you either need to inherit the base class (and add new properties), or add metadata
so it's just kinda useless...what's point if i can just save a node.tscn with a script on it and attach it to other scenes that needs? cause if there's no difference then classes have no reason to exist.
No there’s a multitude of uses for classes, not having to rewrite code is the biggest. If I have ten enemies they can all have the same health. Why create ten scenes with the same script lines written. When code can be reduced it should be. Example, you have a script where you want enemies to spawn every time an enemy dies - you can use a class with a condition statement stating if enemy_dies():
PathSpawn
Then no matter the enemy type that died when you kill one it respawns. Then you didn’t have to write the spawn script on ten enemy types. If you plan on having no variety or spaghetti code sure you can ignore classes. If you want to speed up production, have cleaner, more efficient code then use classes.
@@H3_remix I have no idea what do you mean by reduced code? How do classes reduce code if it's just another script you instance? Its literally just a script saved as .tscn....same thing as writing a script and attaching it where you need it
@@Ceisri you’re missing the fundamental point of classes. If you have ten enemies and they all have 100 health, why would you need to write ten scripts for their health, movement or spawn position. You’re writing much less code because instead od creating ten variables in ten scripts you have one script with one variable. Health. You could then extrapolate it further and add their movement. You can then have their specific mechanics only in their script, but because they’ve inherited the enemy class they don’t need the health variable in each one. Thus you’ve reduced your lines by a minimum of ten in this example. Because your enemy class already has a health variable, or spawn variable set you can write it once and then set each enemy to be a part of the class.
I’m not sure where we have lost each other here. The difference being classes are declarative while nodes and scenes are imperative.
Declarative meaning it doesn’t need to define its control flow. Imperative meaning it’s described step by step in detail.
Are scripts/scenes similar to classes, yes, but they are not the same.
As dor the node with a script attached you’ve created an imperative code. Rather than being declarative as in classes. There is extensive documentation on the godot site about classes and how they function if you have further confusion.
@@H3_remixI think what he's asking is why would you use classes instead of just instancing the scene/code you've already written.
@@H3_remix Multiple instances of the enemy.tscn scene will share the same code file. Then if we export the health variable it can be made unique for each enemy directly in the editor. No need for classes or additional lines of code.
@Queble this is a great tutorial, but I personally would really enjoy some more real-world examples of how classes are better than just instancing scenes!
class vs inheritance? ua-cam.com/video/rJaX19t67AA/v-deo.html
can I mix the 2?
So classes and inheritance are essentially the same thing.
Let's say you have a Entity class with and entity name, then 2 sub classes: Player and Enemy.
These 2 subclasses also would have an entity name, so they would both inherit from the entity class.
This is called inheritance, because we have two subclasses inheriting from the parent class AKA entity.
What you might be talking about, and something I would suggest looking into, is using a component system rather than inheritance