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
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 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.
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!
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 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.
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
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
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
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!
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!!
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 :)
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 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)
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!
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!!
@@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!
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.
@@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!!!
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!
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!
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.
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?
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!!!
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!
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!
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!!
@@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
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.
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.
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 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
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!!
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.
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
that is a very very good point, Ill pin this comment in hope others can see!!
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.
I understand the first comment but I'm still lost on your second comment. Could you explain that a bit more? Thanks!
@@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.
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!
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!
Nice! Btw you can also export the color to get a color picker in the resource ;)
very good tip! thank you very much!
wake up babe, new DevWorm tutorial just dropped.
haha love that!
Poor babe, always being woken up 😞
Nl viewer spotted in the wild
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!
I’m happy it made sense, good luck with your project! If you ever have any questions feel free to ask!
Thank you for the walkthrough tutorial about resources. Hope you can continue doing more of these type of tutorials.
I am so glad to hear that!! Anything specific you have in mind? I would love to try and help!
@@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.
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
they make things so much easier and save so much time!
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
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
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!
Yoooo! Feels like ages since you last dropped! Great video btw!
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!!
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 :)
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!
@@nathanl.4730 ty for your advice :)
I appreciate it very much!! (Srry if I sound like a robot 🤷♂️)
@@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)
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!
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!!
@@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!
Can you make a video about multiplayer?
for sure!! will be working on one soon!!
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.
Wow, how can a video I need come up at the perfect time? 🥰
aw that makes me so happy!! I hope it helps!! if you need anything feel free to let me know!
Literally put out a video of the actual thing I was looking for.
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!!
Could you make a video on how to incorporate limboai state machines with the behavior trees?
I want to create a more in depth limboai tutorial soon!! so Ill for sure implement that in there!
@@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!!!
Hey, dude, nice job. Will you make a slide mechanic mechanic in the future?
Thanks alot because
As you know in the last video the commented to make a video on resources in Godot and you do😊😊😊
of course!! anytime!! if you ever need anything or have any questions feel free to let me know!
@@dev-worm Umm how to manage large games files and everything in godot
for real this can change life thanks for it
resources are actually such a game changer!
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!
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!
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.
nice Tutorial, thanks for sharing
thank you! I hope it was helpful!
How does this work with a spawner?? I want to gradually spawn enemies over time, and also spawn in harder and harder enemies...
Resource in Godot is like viewModel in MVVM mobile arch 👌
that is actually very true!
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?
Bro your actually a goat!
aw man that means the world!! thank you so much! I'm glad it was able to help!
Could You make a video about either destructible tiles or a Rhythm mechanic pls
I will 100% look into it!! thanks for letting me know!
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!!!
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!
Thank you for replying now im gonna work on that!
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 ?
Will you upload a devlog to channel?
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!
excellent
Thank you so much, I hope it was helpful!
nice tips!!
I hope they help!! thank you!
@@dev-worm It sure will! Although I must refactor a lot of things now that I learned this!
im a begginer but thats cool so im saving that for a distant future
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!!
@@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
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.
Can you make a video about making level?
I am actually working on a level manager tutorial right now!! which will kinda cover everything level related!
@@dev-worm Thats only thing left I am allready done with every thing Player eneny art ,sound etc just levels ..
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.
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
I love them conceptually but that is massive deal breaker for me. I use config files instead.
And how can i contact you besides youtube? If it is ok
discord is perfect!! link in description to the server, and then just dm me!
Ok tks🙏🙏
Hello, I am a new developer/coder. Isn't resource just the same as composition?
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.
thank u
of course! I'm so glad it helped!
👾
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
Also, when my player collides with an enemy, he starts to move on his own in a particular direction, how do i stop it
thanks in advance and i freaking love love looooooooove your content! ❤❤❤❤❤❤
@@Aleal3201 yeah
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!!
@@dev-worm thanks bro i love you with all my heart and soul 😍
of course anytime!! I hope it helped a bit!
Woah I’m early
thank you so much!! it means the world!
hi
hello!!
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.
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!