How to use Classes in Godot! - Intermediate Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น • 50

  • @ched4516
    @ched4516 5 หลายเดือนก่อน +20

    This tutorial was much easier to understand on the specifics without going too far off subject. Keep up the good work.

  • @almostleonan938
    @almostleonan938 2 หลายเดือนก่อน +4

    For me as a beginner, that was the best explanation for class I watched. Nice job!

  • @sebashtioon_
    @sebashtioon_ 4 หลายเดือนก่อน +13

    Thank you! Very confused about classes before this but now I understand them. ❤

  • @bahafaaz
    @bahafaaz วันที่ผ่านมา

    Wait that is so powerful. Thank you for very clear explanation!

  • @konvay_vardogr
    @konvay_vardogr 2 หลายเดือนก่อน +1

    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.

  • @kynda
    @kynda 4 หลายเดือนก่อน +3

    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.

  • @GabeNarwhal
    @GabeNarwhal 6 หลายเดือนก่อน +4

    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!

  • @buzzbuzz20xx
    @buzzbuzz20xx 3 หลายเดือนก่อน

    This is just a simple and straightforward way of explaining classes and inheritance!

  • @NathanielMerck-y7j
    @NathanielMerck-y7j 3 หลายเดือนก่อน

    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!

  • @何志颖
    @何志颖 6 หลายเดือนก่อน +4

    Good job,I want to see a video about how to do trade-off between inherit and composition in Godot.

  • @Danachew
    @Danachew 6 หลายเดือนก่อน +3

    A video on building different custom resources would be awesome!

    • @lout160
      @lout160 6 หลายเดือนก่อน +1

      I can confirm. This would be undoubtedly awesome. Very necessary.

  • @xtoo550
    @xtoo550 3 หลายเดือนก่อน

    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!

  • @do_it_like_rei
    @do_it_like_rei 6 หลายเดือนก่อน +1

    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 :)

  • @MathieuHaas68
    @MathieuHaas68 2 หลายเดือนก่อน

    Awesome job truly! This makes it clear for almost anyone!

  • @fvhaudsilhvdfs
    @fvhaudsilhvdfs 6 หลายเดือนก่อน +6

    we crave another custom resources video :)

    • @lout160
      @lout160 6 หลายเดือนก่อน +1

      We do. We crave it!

  • @cbrauny8576
    @cbrauny8576 2 หลายเดือนก่อน

    This tutorial was very helpful, thanks!

  • @legarscringe2853
    @legarscringe2853 2 หลายเดือนก่อน

    Thank you soo much buddy this video was very good

  • @SoyIbrag
    @SoyIbrag 3 หลายเดือนก่อน

    TYSM! Keep up the good work!

  • @Nishisaki405
    @Nishisaki405 4 หลายเดือนก่อน

    This was amazing. Thanks a lot

  • @johnmerriam7844
    @johnmerriam7844 หลายเดือนก่อน

    yes please do the resource tutorial, just as you described here 7:05! thanks! great job.

  • @aahh437
    @aahh437 6 หลายเดือนก่อน +2

    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

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  6 หลายเดือนก่อน

      I'll add that idea to the list! :)

    • @thegameissimple
      @thegameissimple 6 หลายเดือนก่อน

      Use inheritance only when composition is logically impossible. In all other cases prefer composition.
      And don't inherit deeper than two levels.

  • @LouisDoesGames
    @LouisDoesGames 3 หลายเดือนก่อน

    nice video thanks a lot!!

  • @LouisDoesGames
    @LouisDoesGames 3 หลายเดือนก่อน

    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?

  • @AtelicDev
    @AtelicDev 5 หลายเดือนก่อน

    Awesome tutorial!

  • @DanielAraujo92
    @DanielAraujo92 3 หลายเดือนก่อน

    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?

  • @blazenetic
    @blazenetic 6 หลายเดือนก่อน

    Very well done 👍

  • @lout160
    @lout160 6 หลายเดือนก่อน +1

    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.

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  6 หลายเดือนก่อน +4

      Planning on extending this video with a custom resource attack system:)

  • @PhilChilled
    @PhilChilled 4 หลายเดือนก่อน

    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.

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  4 หลายเดือนก่อน +1

      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!

  • @ukrsolid
    @ukrsolid 2 หลายเดือนก่อน

    resources tutorial please, thanks for this Tutorial

  • @lml55
    @lml55 3 หลายเดือนก่อน

    please explain inner class omg bro no one on this platform is explaining this one concept

  • @Sunflower-lk2xo
    @Sunflower-lk2xo 5 หลายเดือนก่อน

    How do you give an instance of a class its own unique variable?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  5 หลายเดือนก่อน

      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

  • @ThePlecoPal
    @ThePlecoPal 2 หลายเดือนก่อน

    I figured out octrees before figuring out what a class meant☠️

  • @PandaManArchives
    @PandaManArchives 2 หลายเดือนก่อน

    class vs inheritance? th-cam.com/video/rJaX19t67AA/w-d-xo.html
    can I mix the 2?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  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

  • @Seisry
    @Seisry 5 หลายเดือนก่อน

    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.

    • @H3_remix
      @H3_remix 5 หลายเดือนก่อน +1

      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.

    • @Seisry
      @Seisry 5 หลายเดือนก่อน

      @@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

    • @H3_remix
      @H3_remix 5 หลายเดือนก่อน

      @@Seisry 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.

    • @harmoen
      @harmoen 4 หลายเดือนก่อน +1

      ​@@H3_remixI think what he's asking is why would you use classes instead of just instancing the scene/code you've already written.

    • @MartynaPanasiuk
      @MartynaPanasiuk 4 หลายเดือนก่อน

      @@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!