Hey Friends! Fair warning: This tutorial is a bit outdated! At some point, I'll get around to making a Godot 4+ version, but for now, I'd recommend checking out my video on the new Export syntax in Godot 4 to get started with some of the new data exporting rules! Thanks for the continued support! Let me know if you'd like to see this or any of my other older tutorials refreshed for the current Godot 4 landscape!
2 years latet and this is still very helpful. Even with outdated syntax ( exports) and stuff, its a great video showcasing the fundemental parts of making an item system in godot. Videos like this are hard to find now because everyone just wants to show off their way to make inventories, instead of just showing people fundementals of items. So thank you even now for this fantastic video!
Glad you found it helpful! Resources are SO powerful, regardless of the application! It’s a bit annoying that you can’t export custom classes (yet), but hopefully that’s resolved in 4.0. Cheers!
Great tutorial! HeartBeast has a couple videos where he compares them to “scriptable objects,” which is really where the structure shines IMO. JSON or CSVs can’t really compare. One neat thing I’ve been playing with are creating base “Item” scenes that allow me to set a resource in the inspector. It’s pretty much like your item scene in the video, but for the world instead of an inventory. Makes placing items around my levels super easy! Thanks for sharing the tutorial, looking forward to more!
Thinking of Resources as Scriptable Objects is perfect! Heartbeast's video is what got me so interested in Resources in the first place - lots of love to him and his channel! I love that idea of creating Item scenes to be placed in the world, too! I use something like this in my current game as a wrapper around my Item Resources (a la export(Resource)) and setting up the item in the inspector OR dragging an already-made one into that Item Scene Instance)! Thanks for the comment!
Depending on your Godot version, you may run into error very early when try to code along. Starting using godot 4 there are errors when trying export or @export the very first variables. var ITEM_NAME is okey - no error, as well as @export var name: String = "" no errror ! :) It takes a while to search but u will find links for both old and new engine commands.
u r right that the video is long. however the resource is a deep subject. now I am aware how the links works amongst the godot class structure. u r a good tutor. please go on with your way. thank you indeed.
Thank you so much for this tutorial! I've been struggling with how to construct an item database of sorts. My current implementation uses one big singleton that contains every item and it's various parameters, but this seems much better!
Great tutorial! Anyone who has played around with unities scriptable objects has played with this kind of data driven design. One pitfall that I think should be mentioned is the danger of storing actual runtime data in your item data. I might have just missed this section in your video, but with this current set up, it seems that you would run into issues when different inventories have the same item type. For example you have 4 cookies in your inventory and a shopkeeper has 5 cookies, with your resource storing the quantity both you and the shopkeeper would be accessing the same resource and therefore the same quantity. There wouldn't be an easy way to buy a cookie, therefore reducing the shopkeepers quantity by one and increasing your quantity by one since they are the same variable. I think the easiest workaround would be to either store the quantity in a separate inventory management script or create an item node which references a resource for all its consts but holds all its variables separately so that any number of them can be instantiated without them interfering with each other.
Your voice has captured me. I am working on an interesting variation of an RPG, and your perspective would be valuable. Obviously you have your own project so I don’t expect any interest, but I’d hate myself I didn’t at least extend the chance to work with you. Now I will finish your voi- video.
I got a little lost on the latter half but this was very helpful. I'm still wrapping my head around resources vs scenes and how resources are integrated. My item class is HIGHLY similar but extends nodes. I then make a scene for each item. I need to understand resources better.
No problem - there's a lot going on behind the scenes, and the difference between some of the object types can be pretty fine. In general, you can use exported variables in nodes or resources (or any other object that extends from the Object type), so it's not necessarily wrong to use nodes. However, using 'extends Resource' in your script allows you to create instances of that resource from the editor window very quickly (these are the .tres files). If you're familiar with object-oriented techniques, creating the Resource script is like defining a class, while creating a Resource of that script's type is like instancing that class. With these .tres files created, you can then call on them in your code to load/save data quickly, and you can easily change all types of information!
@@jacobfoxe4691 It seems extremely handy and clean. The way I was doing it, I couldn't attach a second script, so I didn't know where to add the functionality for individual items without adding it to the general item script and I intuitively knew that wasn't best practice. Thanks for taking the time to respond to me.
Thanks for the video. Very enlightning. I did watch the end credits as well :), and I'm suprised that there arent any game dev videos of the game. The marketing wont happen by itself when you release the game. You need to build a fan base and hype. Create gamedev / showoff videos of the game atleast a year+ before launch to get some traction. (I havent seen any of your game videos. Maybel Ive missed something)
How did you approach the inventory singleton? I tried to make one and I created a dictionary to store all items and a function to load them when one is added but Im pretty sure there should be a better way to do it
does setget work differently in godot 4? managed to get most of it to work using your video about the new syntax, but I don't think you talk about setget
For Godot 4: The syntax for exports is like this @export var my_item : Resource I had to change the item_sprite script quite a bit. Here it is. Mind you I don't use the same naming conventions as him so it won't directly port over but you should easily be able to see the pattern in what needs changed. extends TextureRect @export var my_item : Resource: set = _set_item @onready var my_label = $RichTextLabel func _ready(): if my_item: _set_item(my_item) # Initialize the item if it is set from the start func add_quantity(amount_added : int): my_item.add_quantity(amount_added) _update_label() # Ensure the label is updated func _set_item(new_item : Resource): print("setting item") my_item = new_item self.texture = my_item.get_texture() _update_label() # Update the label with the new item func _update_label(): if my_label and my_item: my_label.bbcode_text = str(my_item.get_quantity())
Could I fill in the resource fields with information obtained from a database? 5:16 And if my armor has a specific ability, how should the code be constructed? 9:26
I’m already using resources for my items, but I really like the idea of separating them into types of item. Finally my sword item won’t have a place to instance placeable objects Quick question though, if I had the line if inventory_item is ITEM: (ITEM being the class name), and it was talking about say the cookie which is a food_item which inherits from the ITEM class would this still return true?
Thanks for checking out this video! I did a little test to confirm this behavior just now: -> "if cookie is ITEM" Returns TRUE because its class (FOOD_ITEM) inherits from the ITEM class. -> Likewise, "if cookie is FOOD_ITEM" ALSO returns true. This is typical behavior for object-oriented languages (like GDScript, and C++ that it's built on top of), and any classes that inherit other classes will also possess those member variables, functions, and un-overridden behaviors. Cheers!
What's the best way to insert, in those items, some properties that are more "instance-local"? For example a "condition" property in the ARMOR_ITEM, that transfers between the inventory item, the dropped item and the equipped item. What would the best solution be? I can't find a sweetspot
Great tutorial and very helpful actually, but could you clear something up for me? Where do you put the function that gives the item it's action? For the cookie to restore health, do you put the function in the base Item class, because the cookie resource itself can't hold the function, right? Then the cookie would hold the parameters such as amount restored, single target, etc that are passed in? And the function itself would get called somewhere else, like in the battle scene or inventory screen? Do you use if statements to sort between functions then for restorative items, battle items, equipment (which you wouldn't eat to restore health)? I'm new to programming and Godot, so I'm trying to piece this bit together. Thanks!
Hey Christopher! Yeah, different classes of Resources can hold their own functionality (and override those of their parents)! I just released a video about it if you'd like to check it out, and you're welcome to ask again if you need further clarification! Cheers!
In Godot 4.1 I tried this twice and each time I get to 17:25 and try and put in the white_shirt.tres I don't see the white t shirt in the editor. I did make my own white tshirt PNG, but I didn't do anything unique with the picture and it should be showing up. Did anyone else get stuck here?
My guess would be a mismatch on the editor version - the syntax in this tutorial was for Godot 3.2 (I think), and it's a lot different for Godot 4+. Otherwise, I'd check to make sure you're exporting the right type of variable to drop-in the PNG. Let me know if that points you in the right direction, or if that just made for more questions haha
@@jacobfoxe4691Well I found out that the $RichTextLabel.bbcode_text = newItem.getQuantity() has the RichTextLabel null when that line is run. For some reason the label is not being created in memory before that line of code is executed. Not familiar enough with Godot, but not sure why the child node is not being created when the ITEM_SPRITE code is running. Maybe someone else knows why this is happening on Godot 4 and not in Godot 3. I can try and load the project in Godot 3 to see if it works there. Also the bbcode_text seems to have been removed in Godot 4. It is still possible to toggle BBCode enabled in the editor, but the syntax no longer exists in the scripting editor. I was able to get this working by redoing it in Godot 3, so I must be doing something wrong in Godot 4.
Hey Friends! Fair warning: This tutorial is a bit outdated! At some point, I'll get around to making a Godot 4+ version, but for now, I'd recommend checking out my video on the new Export syntax in Godot 4 to get started with some of the new data exporting rules!
Thanks for the continued support! Let me know if you'd like to see this or any of my other older tutorials refreshed for the current Godot 4 landscape!
Still a great video for learning the concepts, looking forward to seeing the updated version to use in my games.
2 years latet and this is still very helpful. Even with outdated syntax ( exports) and stuff, its a great video showcasing the fundemental parts of making an item system in godot. Videos like this are hard to find now because everyone just wants to show off their way to make inventories, instead of just showing people fundementals of items. So thank you even now for this fantastic video!
Thanks! I really appreciate it! I'd love to do a Godot 4+ remake of this tutorial, so maybe sometime soon!
This was the tutorial that I didn't know I needed. While I'm not making an RPG, this has so many use cases and now I've got ideas! Thanks for this.
Glad you found it helpful! Resources are SO powerful, regardless of the application! It’s a bit annoying that you can’t export custom classes (yet), but hopefully that’s resolved in 4.0. Cheers!
Once he said, "lets zoom in a little bit so its easier to see", I was liek, "THANK YOU!"
Great tutorial! HeartBeast has a couple videos where he compares them to “scriptable objects,” which is really where the structure shines IMO. JSON or CSVs can’t really compare.
One neat thing I’ve been playing with are creating base “Item” scenes that allow me to set a resource in the inspector. It’s pretty much like your item scene in the video, but for the world instead of an inventory. Makes placing items around my levels super easy!
Thanks for sharing the tutorial, looking forward to more!
Thinking of Resources as Scriptable Objects is perfect! Heartbeast's video is what got me so interested in Resources in the first place - lots of love to him and his channel!
I love that idea of creating Item scenes to be placed in the world, too! I use something like this in my current game as a wrapper around my Item Resources (a la export(Resource)) and setting up the item in the inspector OR dragging an already-made one into that Item Scene Instance)!
Thanks for the comment!
Yep same. I’m also using a base item which just reads properties from the resource while in game. It’s so much better than creating individual scenes.
So nice!, thanks for this bro! Very illustrative keep going!!!
Thank you! This is just what I needed.
Absolutely! Thanks for stopping by! :)
Keke's the real goat fr 🎵🎵
Depending on your Godot version, you may run into error very early when try to code along. Starting using godot 4 there are errors when trying export or @export the very first variables. var ITEM_NAME is okey - no error, as well as @export var name: String = "" no errror ! :) It takes a while to search but u will find links for both old and new engine commands.
ty
Thanks for the tutorial, the idea of using extends to create the different item classes while still sharing functionality was exactly what I needed ☺
u r right that the video is long. however the resource is a deep subject. now I am aware how the links works amongst the godot class structure. u r a good tutor. please go on with your way. thank you indeed.
Thanks for the feedback! I'm glad you found it helpful! :)
Thank you so much for this tutorial! I've been struggling with how to construct an item database of sorts. My current implementation uses one big singleton that contains every item and it's various parameters, but this seems much better!
Great tutorial! Anyone who has played around with unities scriptable objects has played with this kind of data driven design. One pitfall that I think should be mentioned is the danger of storing actual runtime data in your item data. I might have just missed this section in your video, but with this current set up, it seems that you would run into issues when different inventories have the same item type. For example you have 4 cookies in your inventory and a shopkeeper has 5 cookies, with your resource storing the quantity both you and the shopkeeper would be accessing the same resource and therefore the same quantity. There wouldn't be an easy way to buy a cookie, therefore reducing the shopkeepers quantity by one and increasing your quantity by one since they are the same variable. I think the easiest workaround would be to either store the quantity in a separate inventory management script or create an item node which references a resource for all its consts but holds all its variables separately so that any number of them can be instantiated without them interfering with each other.
Your voice has captured me. I am working on an interesting variation of an RPG, and your perspective would be valuable. Obviously you have your own project so I don’t expect any interest, but I’d hate myself I didn’t at least extend the chance to work with you.
Now I will finish your voi- video.
I got a little lost on the latter half but this was very helpful. I'm still wrapping my head around resources vs scenes and how resources are integrated. My item class is HIGHLY similar but extends nodes. I then make a scene for each item. I need to understand resources better.
No problem - there's a lot going on behind the scenes, and the difference between some of the object types can be pretty fine. In general, you can use exported variables in nodes or resources (or any other object that extends from the Object type), so it's not necessarily wrong to use nodes.
However, using 'extends Resource' in your script allows you to create instances of that resource from the editor window very quickly (these are the .tres files). If you're familiar with object-oriented techniques, creating the Resource script is like defining a class, while creating a Resource of that script's type is like instancing that class.
With these .tres files created, you can then call on them in your code to load/save data quickly, and you can easily change all types of information!
@@jacobfoxe4691 It seems extremely handy and clean. The way I was doing it, I couldn't attach a second script, so I didn't know where to add the functionality for individual items without adding it to the general item script and I intuitively knew that wasn't best practice. Thanks for taking the time to respond to me.
Hi, I'm really curious about this workaround about cyclic dependency with singletons you were talking about here 3:50
so good this tutorial! 10/10
this looks really exciting!! im a total beginner rn hope to learn to apply this stuff soon. I've never done any coding before LOL
Thanks for the video. Very enlightning. I did watch the end credits as well :), and I'm suprised that there arent any game dev videos of the game. The marketing wont happen by itself when you release the game. You need to build a fan base and hype. Create gamedev / showoff videos of the game atleast a year+ before launch to get some traction. (I havent seen any of your game videos. Maybel Ive missed something)
This is a really great video
How did you approach the inventory singleton? I tried to make one and I created a dictionary to store all items and a function to load them when one is added but Im pretty sure there should be a better way to do it
does setget work differently in godot 4? managed to get most of it to work using your video about the new syntax, but I don't think you talk about setget
New to Godot. why did you need the pointer for the get_texture func at 15:45?
Godot type casting doesnt cover pointers to textures?
For Godot 4:
The syntax for exports is like this
@export var my_item : Resource
I had to change the item_sprite script quite a bit. Here it is. Mind you I don't use the same naming conventions as him so it won't directly port over but you should easily be able to see the pattern in what needs changed.
extends TextureRect
@export var my_item : Resource:
set = _set_item
@onready var my_label = $RichTextLabel
func _ready():
if my_item:
_set_item(my_item) # Initialize the item if it is set from the start
func add_quantity(amount_added : int):
my_item.add_quantity(amount_added)
_update_label() # Ensure the label is updated
func _set_item(new_item : Resource):
print("setting item")
my_item = new_item
self.texture = my_item.get_texture()
_update_label() # Update the label with the new item
func _update_label():
if my_label and my_item:
my_label.bbcode_text = str(my_item.get_quantity())
You are a life saver, thank you so much for sharing!
@@nuller52 do you have a discord? Also thanks. I forgot I made this comment.
@@visibletoallusersonyoutube5928 Same as youtube nickname
@@visibletoallusersonyoutube5928 yes, same as youtube nickname
@@nuller52 sent
Could I fill in the resource fields with information obtained from a database? 5:16
And if my armor has a specific ability, how should the code be constructed? 9:26
I’m already using resources for my items, but I really like the idea of separating them into types of item. Finally my sword item won’t have a place to instance placeable objects
Quick question though, if I had the line if inventory_item is ITEM: (ITEM being the class name), and it was talking about say the cookie which is a food_item which inherits from the ITEM class would this still return true?
Thanks for checking out this video! I did a little test to confirm this behavior just now:
-> "if cookie is ITEM" Returns TRUE because its class (FOOD_ITEM) inherits from the ITEM class.
-> Likewise, "if cookie is FOOD_ITEM" ALSO returns true.
This is typical behavior for object-oriented languages (like GDScript, and C++ that it's built on top of), and any classes that inherit other classes will also possess those member variables, functions, and un-overridden behaviors. Cheers!
What's the best way to insert, in those items, some properties that are more "instance-local"? For example a "condition" property in the ARMOR_ITEM, that transfers between the inventory item, the dropped item and the equipped item. What would the best solution be? I can't find a sweetspot
Great tutorial and very helpful actually, but could you clear something up for me? Where do you put the function that gives the item it's action? For the cookie to restore health, do you put the function in the base Item class, because the cookie resource itself can't hold the function, right? Then the cookie would hold the parameters such as amount restored, single target, etc that are passed in? And the function itself would get called somewhere else, like in the battle scene or inventory screen?
Do you use if statements to sort between functions then for restorative items, battle items, equipment (which you wouldn't eat to restore health)?
I'm new to programming and Godot, so I'm trying to piece this bit together. Thanks!
Hey Christopher! Yeah, different classes of Resources can hold their own functionality (and override those of their parents)! I just released a video about it if you'd like to check it out, and you're welcome to ask again if you need further clarification! Cheers!
@@jacobfoxe4691 Thanks! I'll check it out this morning. It's really been puzzling me.
stardew valley music fits perfectly
In Godot 4.1 I tried this twice and each time I get to 17:25 and try and put in the white_shirt.tres I don't see the white t shirt in the editor. I did make my own white tshirt PNG, but I didn't do anything unique with the picture and it should be showing up. Did anyone else get stuck here?
My guess would be a mismatch on the editor version - the syntax in this tutorial was for Godot 3.2 (I think), and it's a lot different for Godot 4+. Otherwise, I'd check to make sure you're exporting the right type of variable to drop-in the PNG. Let me know if that points you in the right direction, or if that just made for more questions haha
@@jacobfoxe4691Well I found out that the $RichTextLabel.bbcode_text = newItem.getQuantity() has the RichTextLabel null when that line is run. For some reason the label is not being created in memory before that line of code is executed. Not familiar enough with Godot, but not sure why the child node is not being created when the ITEM_SPRITE code is running. Maybe someone else knows why this is happening on Godot 4 and not in Godot 3. I can try and load the project in Godot 3 to see if it works there. Also the bbcode_text seems to have been removed in Godot 4. It is still possible to toggle BBCode enabled in the editor, but the syntax no longer exists in the scripting editor. I was able to get this working by redoing it in Godot 3, so I must be doing something wrong in Godot 4.
Godot 4 definitely has exportable custom resources. It's too obviously missing piece for remotely data-driven system.
😀
Um... good luck with dealing with hundreds (thousands) of unique items/characters.
pleaceeee make a full inventory system i really need that