Custom Resource are a MUST KNOW in Godot | Complete Tutorial

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

КОМЕНТАРІ • 105

  • @nadadenadak
    @nadadenadak Місяць тому +29

    One additional thing, you can use the class name as the type of the resource. This way you have auto complete working. So instead of var resource : Resource, you can do var resource :calc_resource

    • @dev-worm
      @dev-worm  Місяць тому +8

      that is a very very good point, Ill pin this comment in hope others can see!!

  • @larsthomasdenstad9082
    @larsthomasdenstad9082 Місяць тому +23

    Great video.
    Just a couple of comments. I am not sure why you use the numeric value for the enum in your match-branches, you can use the named value `ADD`, `SUBTRACT`, etc, in the match-branches, that allows the code to keep working even if you change the internal order of the enum or add more enum entries.
    Also, when you add a class_name to the resource by extending it, you can accept the derived type in the scripts instead of getting a `Resource`, which will give you completion on the type, and make sure a generic resource isn't assigned to the class making it fail at runtime.

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

      I understand the first comment but I'm still lost on your second comment. Could you explain that a bit more? Thanks!

    • @larsthomasdenstad9082
      @larsthomasdenstad9082 Місяць тому +3

      @@bradleywood1984 If you look at 18:05 he extends `Resource` with `class_name enemy_type`.
      At 28:05, on line 3, he accepts a `Resource`. Here you can choose to instead accept the more derived type of `enemy_type`, making it so you can only drop resources that are actually enemy types. This will make the UI better, because it will only accept these specialized resources and the script fail less often because you know it is indeed an instance of this derived resource as well as getting better intellisense while editing.
      I hope this is clearer.

  • @Drewbacca77
    @Drewbacca77 Місяць тому +4

    Thanks DevWorm! This video dropped when I was coming around to the idea of using resources to solve some of my level data problems, but most videos out there were like “they’re great!”. You showed us how to use them! Much appreciated!

    • @dev-worm
      @dev-worm  Місяць тому

      so happy to hear the timing was perfect!! and I am happy to hear it helped!! if you ever need anything feel free to ask!

  • @TobbeyDude
    @TobbeyDude Місяць тому +4

    Nice! Btw you can also export the color to get a color picker in the resource ;)

    • @dev-worm
      @dev-worm  28 днів тому

      very good tip! thank you very much!

  • @ishanj2021
    @ishanj2021 Місяць тому +24

    wake up babe, new DevWorm tutorial just dropped.

    • @dev-worm
      @dev-worm  Місяць тому +2

      haha love that!

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

      Poor babe, always being woken up 😞

    • @ThaFritz
      @ThaFritz 6 днів тому

      Nl viewer spotted in the wild

  • @trevorbrowning8928
    @trevorbrowning8928 23 дні тому

    I've been trying to understand how to set up a system using resources from a previous tutorial and wasn't quite understanding it until your video, so thank you so much for this, I appreciate it!

    • @dev-worm
      @dev-worm  22 дні тому

      I’m happy it made sense, good luck with your project! If you ever have any questions feel free to ask!

  • @desireelustre
    @desireelustre Місяць тому +3

    Thank you for the walkthrough tutorial about resources. Hope you can continue doing more of these type of tutorials.

    • @dev-worm
      @dev-worm  Місяць тому

      I am so glad to hear that!! Anything specific you have in mind? I would love to try and help!

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

      @@dev-worm Well I am experimenting myself but still don't get the full capacity of node base state machine. I really like 2d platformers and been trying to create one to no avail. Its been 4 years now since I found Godot and I still have not finished even a working sidescrolling game.

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

    The best thing I love about resources is you can nest them with local resources. I can make an Effect resource and just add new instances of Affect resource and modify them there locally

    • @dev-worm
      @dev-worm  Місяць тому

      they make things so much easier and save so much time!

  • @Hectorius1981
    @Hectorius1981 26 днів тому

    DevWorm, dude! Thanx for your time and effort you put in to this videos. I'm so great full. I just started with "dev", have never done something like this befor. But your videos rely helps me understand better and easy. Thanx

  • @BetaNights
    @BetaNights 26 днів тому

    Yo, thanks a ton for this tutorial, dude! I've seen a handful of Custom Resource tutorials floating around in my recommended here and there, and while I've been able to understand the *point* of Custom Resources, I feel like this video easily did the best job at helping me actually see how you'd use them in practice.
    As a new, aspiring game dev learning Godot, thank you! Between learning this and how to use components vs. inheritance effectively, I feel like this will help a lot with my own projects. The more I can keep things clean and modular and reusable, the better lol

    • @dev-worm
      @dev-worm  25 днів тому

      I am so glad to hear that!! thank you so much for the kind words! and i am just so happy it was helpful! if you come across any issues or have any questions feel free to let me know! I am here for you! goodluck using them in your own projects!

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

    Yoooo! Feels like ages since you last dropped! Great video btw!

    • @dev-worm
      @dev-worm  Місяць тому

      it has been a little bit!! life got a bit crazy!! but I have some amazing tutorials planned that I think will be so beneficial! glad you liked the video! your support means the world to me!!

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

    hi! your videos are super helpful with getting started on godot and they really taught me how to get some basic stuff made in the engine, so tysm for that!
    i was also wondering if maybe you had any tutorials on making a turn based combat game that's got randomly spawned fights in certain areas, but other areas with no spawning (kinda like the bushes in pokemon)? also if it had different in-battle menu's that led to like a regular attack, one that led to another small menu with different magic consuming attacks, and also a run function. i've been struggling a lot with trying to find something that could help me with making something like this as most tutorials i've seen have just had the bare minimum that doesn't really expand much.
    anyways, your vids are incredible, keep up the great work :)

    • @nathanl.4730
      @nathanl.4730 Місяць тому

      Hey! If you're gonna make your own unique game there won't be a tutorial for everything, just break your problem into smaller pieces and you should find tutorials or at least some information on how to do these smaller pieces. It's also how you're going to learn the most and feel like you're getting better at it. Once you know all the basics of godot just dive right in otherwise you'll be stuck in tutorial hell for a while trust me. Make your mistakes and learn from them!

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

      @@nathanl.4730 ty for your advice :)
      I appreciate it very much!! (Srry if I sound like a robot 🤷‍♂️)

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

      ​@@soozlethay If you want to make something pokemon style you should look into area2d for the battle trigger, for the battle itself you should look on how to change scenes, for the menu it is all about UI. If you can't find tutorials about the exact game you want to make, you should instead look for tutorials on each system you want to implement. (For the battle ui I believe heartbeast did something on his mobile game tutorial, but i think it might be outdated)

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

    Mulitply! Every time you listed or mention the enums I was hoping you would reach the multiply one, but you always stop at the division, but then you select it and still didn't notice! You really were focused on explaining the Resource 😂. Thank you very much!

    • @dev-worm
      @dev-worm  Місяць тому

      haha!! I love that you noticed that! I had no idea I was doing that lol!! I hope the tutorial was able to help!! and of course anytime if you ever need anything feel free to ask!!

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

      @@dev-worm Actually I've been using resources here and there but didn't know I could create variatons directly from the inspector, I always did a variable of that type and do them from there. Always something to learn!

  • @kjjr2bk696
    @kjjr2bk696 Місяць тому +7

    Can you make a video about multiplayer?

    • @dev-worm
      @dev-worm  Місяць тому +1

      for sure!! will be working on one soon!!

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

      The setup in Multiplayer in Godot 4.0: Scene Replication is an absolute must for any multiplayer projects I make. I would've never thought to use the multiplayer spawner to spawn levels to facilitate scene changes without it. Or using 2 synchronizers for the player character, one for syncing and one for player input.

  • @오예찬-v5e
    @오예찬-v5e Місяць тому +1

    Wow, how can a video I need come up at the perfect time? 🥰

    • @dev-worm
      @dev-worm  Місяць тому +1

      aw that makes me so happy!! I hope it helps!! if you need anything feel free to let me know!

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

    Literally put out a video of the actual thing I was looking for.

    • @dev-worm
      @dev-worm  Місяць тому

      aw! that is so amazing to hear!! I am so glad and I really hope it proved to be helpful! If you have any questions feel free to ask!!

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

    Could you make a video on how to incorporate limboai state machines with the behavior trees?

    • @dev-worm
      @dev-worm  Місяць тому +1

      I want to create a more in depth limboai tutorial soon!! so Ill for sure implement that in there!

    • @MrCoolguy106
      @MrCoolguy106 29 днів тому +1

      @@dev-worm Yay! Limboai state machines and behavior trees are super cool but the docs on how to use them together weren't that helpful for me, and I imagine that it would be a powerful thing to understand. I love your tutorials and have incorporated a lot of your lessons into my zelda-like "dream game" im making. Thank you!!!

  • @ParsaGohari-o9k
    @ParsaGohari-o9k Місяць тому

    Hey, dude, nice job. Will you make a slide mechanic mechanic in the future?

  • @PrakharKesharwani-ly2jd
    @PrakharKesharwani-ly2jd Місяць тому

    Thanks alot because
    As you know in the last video the commented to make a video on resources in Godot and you do😊😊😊

    • @dev-worm
      @dev-worm  Місяць тому

      of course!! anytime!! if you ever need anything or have any questions feel free to let me know!

    • @PrakharKesharwani-ly2jd
      @PrakharKesharwani-ly2jd Місяць тому

      @@dev-worm Umm how to manage large games files and everything in godot

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

    for real this can change life thanks for it

    • @dev-worm
      @dev-worm  Місяць тому

      resources are actually such a game changer!

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

    For argument sake, if I wanted to have the enemies generated randomly, is there a way for me to randomly assign resources to the enemies in the scene? Could I first check and see how many enemies are in the seen and then load randomly the resources needed for each enemy? Trying to wrap my head around it! Thanks!

    • @dev-worm
      @dev-worm  Місяць тому +2

      you could preload all the resource files into variables at the top of the enemy_base script, and then during the on_ready function choose one at random and assign it to the resource variable through the script. I think that would be the best way to do it!! I hope that helps!

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

    This is nice. Came after I really started learning about Resources so not really useful for me, but would've ben great as a beginner (though I do wonder if I would've understood it as well as I do now).
    Currently making a game with a modular map layout that uses scenes to represent rooms that could be aligned to each other in a grid and in that system I have a resource script to define a few things about the room, scene file that holds everything visual as well as handles any random toggles I have (like whether or not a door is open, what location it is, any variances beacuse of it, etc.) a dictionary of vector2 keys to define the grid it aligns to (for fitting rooms into a generated map) and the doors it potentially can have in a given 'cell' for the room (also for generating the rooms in a map). I might put more into the resource, but that's how it is for the time being.

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

    nice Tutorial, thanks for sharing

    • @dev-worm
      @dev-worm  Місяць тому

      thank you! I hope it was helpful!

  • @TimLippert
    @TimLippert 27 днів тому

    How does this work with a spawner?? I want to gradually spawn enemies over time, and also spawn in harder and harder enemies...

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

    Resource in Godot is like viewModel in MVVM mobile arch 👌

    • @dev-worm
      @dev-worm  Місяць тому

      that is actually very true!

  • @wolfiechica
    @wolfiechica 27 днів тому

    Okay but if you had a resource that you wanted to be a basis with pre-programmed fields (IE Red Enemy's resource always has the speed built into the resource itself) but then in a scene only wanted it to affect the one copy of the red enemy itself (or say you had 10 red enemies at once), will each of the nodes track updates to the ENEMY instance of the resource, or will all of them try to update the ORIGINAL resource?
    Edit - oh... and one more thing. If they do track individually, are there any safety considerations for queue_free() we should be considering?

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

    Bro your actually a goat!

    • @dev-worm
      @dev-worm  Місяць тому

      aw man that means the world!! thank you so much! I'm glad it was able to help!

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

    Could You make a video about either destructible tiles or a Rhythm mechanic pls

    • @dev-worm
      @dev-worm  Місяць тому

      I will 100% look into it!! thanks for letting me know!

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

    Damn! this video is a big help, can this resource be anything? like weapon maker or weapon randomizer or even be a random drop something? its just pop up in my head when i understand how it works but i am unsure about the idea if it works, please reply i need answers. THANK YOUUUU!!!

    • @dev-worm
      @dev-worm  Місяць тому +1

      yes!!! they can for the most part be made into anything, its just they way you go about creating it!! all those examples you mentioned are actually all good resource examples!

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

      Thank you for replying now im gonna work on that!

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

    do you think its better or worst to just have a JSON database for everything making it global and just load it once on game start and reference it ?

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

    Will you upload a devlog to channel?

    • @dev-worm
      @dev-worm  Місяць тому +1

      soon!! just havent had too much time recently due to life stuff going on, but I for sure want to document my games and beable to share what im working on as well as creating tutorials! I really like the projects Im working on so I would love to share them really soon!

  • @tiangming
    @tiangming 22 дні тому

    excellent

    • @dev-worm
      @dev-worm  22 дні тому

      Thank you so much, I hope it was helpful!

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

    nice tips!!

    • @dev-worm
      @dev-worm  Місяць тому +1

      I hope they help!! thank you!

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

      ​@@dev-worm It sure will! Although I must refactor a lot of things now that I learned this!

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

    im a begginer but thats cool so im saving that for a distant future

    • @dev-worm
      @dev-worm  Місяць тому

      sounds amazing! make sure you really focus on the beginner stuff because itll build that foundation for you that will be so necessary!! if you ever have any questions feel free to ask!!

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

      @@dev-worm no question so far but i used your tilemap tutorial to help me with a college project (im doing a game in godot for a subject). was really helpful

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

    One thing annoying about godot is absence of code overrides for things inherited from the parent. Godot wants you to use the UI for value changes(there are ways to code it but its annoying for my prototype) and any identical functions override the whole function.

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

    Can you make a video about making level?

    • @dev-worm
      @dev-worm  Місяць тому +2

      I am actually working on a level manager tutorial right now!! which will kinda cover everything level related!

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

      @@dev-worm Thats only thing left I am allready done with every thing Player eneny art ,sound etc just levels ..

  • @carpenterblue
    @carpenterblue 15 днів тому

    my biggest issue with resources is that if I change the name of a exported variable, all the resources extending that class break and lose values.

    • @dev-worm
      @dev-worm  11 днів тому

      that is true. I guess that would be a pretty big con, but even with that resources are still the for sure way to go in a lot of different instances

    • @carpenterblue
      @carpenterblue 11 днів тому

      I love them conceptually but that is massive deal breaker for me. I use config files instead.

  • @ParsaGohari-o9k
    @ParsaGohari-o9k Місяць тому

    And how can i contact you besides youtube? If it is ok

    • @dev-worm
      @dev-worm  Місяць тому

      discord is perfect!! link in description to the server, and then just dm me!

    • @ParsaGohari-o9k
      @ParsaGohari-o9k Місяць тому

      Ok tks🙏🙏

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

    Hello, I am a new developer/coder. Isn't resource just the same as composition?

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

      Composition is really just the idea of giving an object more functionality through the use of multiple, single responsibility, components.
      " Greater than the sum of its parts "
      So yes, any Object that uses a Component script to access a Resource for functionality is Composition.

  • @QuanNguyen-cr7
    @QuanNguyen-cr7 Місяць тому

    thank u

    • @dev-worm
      @dev-worm  Місяць тому

      of course! I'm so glad it helped!

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

    👾

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

    hello devworm, i want to use resources for enemy logic, but i have already made an enemy logic in godot, which is as follows:
    extends CharacterBody2D
    @onready var animations = $AnimationPlayer
    @export var limit = 0.5
    @export var speed = 20
    @export var endPoint: Marker2D
    var startPos
    var endPos
    func _ready() -> void:
    startPos = position
    endPos = endPoint.global_position

    func updateVelocity():
    var moveDirection = (endPos - position)
    if moveDirection.length() < limit:
    change_direction()
    velocity = moveDirection.normalized() * speed

    func _physics_process(delta: float) -> void:
    updateVelocity()
    move_and_slide()
    handleCollision()
    updateAnimation()
    func change_direction():
    var tempEnd = endPos
    endPos = startPos
    startPos = tempEnd

    func updateAnimation():
    if velocity.length() == 0:
    if animations.is_playing():
    animations.stop()
    else:
    var direction = "down"
    var normalized_velocity = velocity.normalized()
    if normalized_velocity.x < -0.8:
    direction = "right"
    elif normalized_velocity.x > 0.8:
    direction = "left"
    elif normalized_velocity.y < -0.8:
    direction = "up"
    animations.play("walk" + direction)
    func handleCollision():
    for i in get_slide_collision_count():
    var collision = get_slide_collision(i)
    var collider = collision.get_collider()
    print_debug(collider.name)
    can you tell me how can i incorporate resources now

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

      Also, when my player collides with an enemy, he starts to move on his own in a particular direction, how do i stop it

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

      thanks in advance and i freaking love love looooooooove your content! ❤❤❤❤❤❤

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

      @@Aleal3201 yeah

    • @dev-worm
      @dev-worm  Місяць тому

      hey so of course a resource would be perfect for this, just like in the video I covered the enemy_stats example, this here is sort of the same thing!! It would be hard for me to explain it over text but if you can possible dm on discord id love to walk you through it! But everything from the video should work perfectly for this example!!

    • @Historymadefun89
      @Historymadefun89 27 днів тому

      @@dev-worm thanks bro i love you with all my heart and soul 😍

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

    • @dev-worm
      @dev-worm  Місяць тому

      of course anytime!! I hope it helped a bit!

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

    Woah I’m early

    • @dev-worm
      @dev-worm  Місяць тому

      thank you so much!! it means the world!

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

    hi

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

    As for the enum, you’d be better off using this syntax:
    ```
    match symbol:
    SYMBOL_TYPES.ADD:

    SYMBOL_TYPES.SUBTRACT:

    SYMBOL_TYPES.MULTIPLY:

    SYMBOL_TYPES.DIVIDE:

    ```
    Way more readable, of course. And that way, even if you reorder the enum later, you won’t break your code.

    • @dev-worm
      @dev-worm  Місяць тому +1

      that is a good point, thank you it completely washed over my head and have no idea why! For some reason I was thinking array!