It's important to note that using Resources to save data is potentially dangerous for the user in some projects. Checkout this video which explains this further, and also provides and alternative method for handling saves :) ruclips.net/video/mI4HfyBdV-k/видео.html
It's important to mention that resources can store any function or object, even a virus. So if you are using a system like this, you should probably tell people not to download external saves and such
Oh jeez, never mind then you're correct a person could put logic in the resource to harm my players. X_X Darn I was starting to like this system. It isn't bad though.
Incredible video, thank you. I love the way you just fly through it without labouring anything, works very well for me. Reminds me of fireship. Nice work mate
Thank you! This was very clear intro on using Resources in general. I have quite complex roguelike game/engine I've worked on and off, using Unity and SadConsole first and now Godot. I've tried to keep everything as decoupled as possible from these frameworks/tools, only using them for rendering and exporting. But this convinced me to commit more fully to Godot, and refactor my json-based data system into Resources.
note for people reporting that Resource save data could be manipulated. If you save it as a .res instead of .tres it saves it as unreadable data (in a text file) So this is an alternative
@@hw2007 I do not know the answer to that. This was mainly in reference to if people just open the tres files in a text file editor, they can easily see and edit it. If using res, they cannot.
Great video, straight and to the point. I know using resources has potential for malicious software if someone downloads saves online but it's on them for downloading from the internet. Custom resources are much easier on the game developer.
Hello when you say at @7:50 about using this in in our own game and defining methods, can you show how this is done please? I am a beginner and this is a crucial element of misunderstanding for me and example would be helpful. Thank you
"it is just so straight forward to load and everything is just perfect" Me who's here because I've spent 3 days trying to get it to properly save an inventory system because there was no way for me to know that I was only saving pointer references essentially and no tutorial ever showed as much: 😲
Hie nice video but l am looking for help. My game has these 2 scenes which are health and wealth. These two are independent of each other because l need to instantiate them in multiple different scenes. These scenes can or not exist simultaneously. The thing is in my main game file when changes occur to the wealth or health but then l try to access another file with only one of these. When l return to the file none of the changes would have been saved. The save function is in the process function can u help me solve this problem
Oh ok for sure! I'll try to explain it here. I'm not by my computer for a few more days, so it's tough to format this on mobile. So the json file is essentially a big dictionary of items. I usually put each item on the root of the file, and then each of those items contains a sub dictionary. The sub dictionary of each item then contains all the information you'd like to store. e.g. Display Name, Description, Cost, etc. This means that each item will have a unique array of all the required properties. You might also want to download a .json editor if your file gets too large, since it's easier to manage consistentency in the item. Finally just remember to keep the root names of each item the same! Usually these aren't used for the in game display name, which creates less bugs (since you'll be accessing the items according to this string; their UID). Hope this helps!
Since the resource file was loaded, its content of player data could be changed. Duplicate it so that player data in the resource file is left untouched, as a save file should.
Question, Say both my inventory and item are custom rwsources and it support item stacking, will it save the sub resources whose amount changed before? I'm not sure if I'm explaining it correctly. The point is, if we make save function for the inventory will the sub resources (items) states be saved too?
Yes, this system will save all sub resources attached to another custom Resource. If you don't want this behavior, you could pass in one of the flags defined in the docs :)
@@queblegamedevelopment4143 Another question please, Sensei. Does it include some bunch on properties from my item class, like if I include var locked = false, then I use a button to turn the property to true then save it. will it remain true?
Player data would simply store any data you'd want to save to a file. To save the players location, you'd have a player scene somewhere in your game with all the controls attached to it's own script. Then, when you save the game, simply store the player's position vector to this file in any manor you'd like. Upon loading, all you have to do is retrieve this information, then apply it to the player's position when they spawn in
@@queblegamedevelopment4143 so for the save ud wanna save EVERYTHING like npc locations and all that, would that be the same concept except with npcData? and same with everything else?
I feel like I'm missing something with this when I try, did you add the PlayerData script to autoload or something??? Did I just miss that or something?
Is the resource file editable outside of the game, ie could a player open up the save file and just tweak the health to 200? Does the resource tool have a way to encrypt the file to prevent player tampering?
Yes it is editable, but you can also encrypt it if you want with open_encrypted or open_encrypted_with_pass (you can read up on their functionality on the Godot docs in FileAccess)
You can also do this. You can save them as .tres which makes it readable and editable in a text file But you can use .res which makes it just data and unreadable in a text file.
Thanks for the great video for me as an beginner!! Is there any way to encrypt the savedata since the tres file can be viewed as plain text? Thanks again for the tutorial.
Just watched very helpful. Is that possible you could make another tutorial to show how to use both Json and custom resource together for like big amount of items/gears/quests/...etc? Thanks anyway. @@queblegamedevelopment4143
Great explanation!! In our current project I am also at the point to Check for the best possibility in saving gamestate with the necessary information. I am currently using dict with json in ecrypted format. Is encryption somehow also working with your approach? I mean we cannot let the player of the Game just use notepad to edit its savefile😆
Thank you! Yes, there is a way to encrypt the save resources, and it's actually pretty straightforward! I do have a tutorial lined up to be recorded (which will cover this), but it will probably be a while before I have time to do so :/ I would suggest checking out these 2 links though: kidscancode.org/godot_recipes/4.x/basics/file_io/index.html docs.godotengine.org/en/stable/classes/class_fileaccess.html I think the docs cover how to use the save/load encrypted methods briefly, but that's what you'll want to look at :)
I'll need to try this with a POCO for the sub-class I guess. If it can handle that properly then this will make Godot insanely good and likely my engine of choice. Edit.... Wait a second... actually no that I think on you are using the .new() method meaning those are instances of the resource so say 1 apple is green and the other is red. Changing 1 wont change the other... Pretty cool, in Unity I'd go about converting SO data to POCO to avoid serialization issues...
it is a bad idea to use resource files over json for save files, resource files is not safe, they can contain functions that can contain malicious code, you should only allow resources that you the developer have made and never allow any from user land to be loaded.
Typically you don't have to worry about this, but yes, if you're encouraging players to download workshop items or external files, you should probably look at encoding the files
@@queblegamedevelopment4143 So what's the alternative? json files are a mess to load and save. More a mess to attach the data to the correct spots. Unless you use the resource as a file manager that distributes the data where it needs to go. What if I have 50 enemies and a level that needs saving... There has to be a better way.
You should generally only be concerned about a potential security risk if the player will be downloading files from external sources (steam workshop or mods), but obviously this would be the user's fault if they're downloading files from a sketchy website or untrusted source. In the case that users are downloading custom files though, you should look into encoding the save files.
@@queblegamedevelopment4143 I'm testing json files for holding static data like an item list, then assigning it internally to a resource. Then I can save the resource as part of my save. It's only a test game until I learn more so I'm all good. Hey, thanks so much for the reply. :) And the video. resource files feel like C# static classes, once I got the jest of them.
Thank you for pointing this out! I'm trying to get around to making a video explaining when and when to not use this system, and also explain the obvious exploitation that can occur 👍
@@proximacentauri1172Yeah, but I feel like "that's their own fault" only goes up to a point. Like, if a gun dealer sells a gun to an incompetent person, and then they shoot someone on the street because they weren't being careful, the dealer would get in trouble because they sold a gun to an incompetent person. Same deal here, the player makes a fatal mistake, and because the developer put all responsibility on them, they suffer disastrous consequences.
it's fair, maybe if your game includes a save system like this then you can put a big DISCLAIMER saying hey don't load random shit from online. if you do you oculd get viruses or whatever. @@pointyorb I'm using this for a simple hour tracking app that I'm making on my PC in order to track how many hours I've done a specific activity for. in this case there is really no reason to encrypt the data because I'm never going to download someone else's "save" this way nor would anyone else. it's simply to store a couple of variables such as the amount of hours i've done the activity for and what the activity's name is
It's important to note that using Resources to save data is potentially dangerous for the user in some projects.
Checkout this video which explains this further, and also provides and alternative method for handling saves :)
ruclips.net/video/mI4HfyBdV-k/видео.html
It's important to mention that resources can store any function or object, even a virus. So if you are using a system like this, you should probably tell people not to download external saves and such
Thank you. I don't know that.
Oh jeez, never mind then you're correct a person could put logic in the resource to harm my players. X_X Darn I was starting to like this system. It isn't bad though.
You should checkout my newest save load system (I go over how to fix this exploit) :)
honestly if anyone is downloading random saves, then thats on them. gotta be safe on the internet
@@DEADEYESTUDIO yup, i think this is just something to be aware of
Incredible video, thank you. I love the way you just fly through it without labouring anything, works very well for me. Reminds me of fireship. Nice work mate
this and the loading .json static data video... subscribed.
Thank you! This was very clear intro on using Resources in general. I have quite complex roguelike game/engine I've worked on and off, using Unity and SadConsole first and now Godot. I've tried to keep everything as decoupled as possible from these frameworks/tools, only using them for rendering and exporting. But this convinced me to commit more fully to Godot, and refactor my json-based data system into Resources.
note for people reporting that Resource save data could be manipulated.
If you save it as a .res instead of .tres it saves it as unreadable data (in a text file)
So this is an alternative
Couldn't a .res file be read by a different godot project made by the attacker? Then they could write a malicious .res using that same godot project?
@@hw2007 I do not know the answer to that.
This was mainly in reference to if people just open the tres files in a text file editor, they can easily see and edit it.
If using res, they cannot.
Even though my english is crap the way you teach it makes me feel smart because i understand everything, thank you very much for your content!
Great video, straight and to the point. I know using resources has potential for malicious software if someone downloads saves online but it's on them for downloading from the internet. Custom resources are much easier on the game developer.
Great video, will definitely implement it on my game!
Thank you for all the help. Now I understand resource classes.
Very nice and clean!
Hello when you say at @7:50 about using this in in our own game and defining methods, can you show how this is done please? I am a beginner and this is a crucial element of misunderstanding for me and example would be helpful. Thank you
Very helpful video, keep it up!
very useful video, thank you!
how do you check if the Save File exists so that the game doesn't give an error when you try to load and there is no save file
"it is just so straight forward to load and everything is just perfect"
Me who's here because I've spent 3 days trying to get it to properly save an inventory system because there was no way for me to know that I was only saving pointer references essentially and no tutorial ever showed as much: 😲
if i use resources to save, i have to move all my methods involving variables in main to the playerdata class, right?
Great video thank you!
Great video, thanks!
Hie nice video but l am looking for help. My game has these 2 scenes which are health and wealth. These two are independent of each other because l need to instantiate them in multiple different scenes. These scenes can or not exist simultaneously. The thing is in my main game file when changes occur to the wealth or health but then l try to access another file with only one of these. When l return to the file none of the changes would have been saved. The save function is in the process function can u help me solve this problem
Any chance you could post an example "item lookup" Json file? I'm working to implement that next in a game I'm developing ❤
Yeah ofc!
Do u mean like an example line of code for accessing an item, or an example json file?
@@queblegamedevelopment4143 I'm interested in the JSON itself just so I can visualize how to fit "a lot of I formation" about one item in there.
Oh ok for sure!
I'll try to explain it here. I'm not by my computer for a few more days, so it's tough to format this on mobile.
So the json file is essentially a big dictionary of items.
I usually put each item on the root of the file, and then each of those items contains a sub dictionary.
The sub dictionary of each item then contains all the information you'd like to store. e.g. Display Name, Description, Cost, etc.
This means that each item will have a unique array of all the required properties.
You might also want to download a .json editor if your file gets too large, since it's easier to manage consistentency in the item.
Finally just remember to keep the root names of each item the same! Usually these aren't used for the in game display name, which creates less bugs (since you'll be accessing the items according to this string; their UID).
Hope this helps!
Nice one. What is the reason for duplicating the loaded player data?
Since the resource file was loaded, its content of player data could be changed. Duplicate it so that player data in the resource file is left untouched, as a save file should.
Question,
Say both my inventory and item are custom rwsources and it support item stacking, will it save the sub resources whose amount changed before?
I'm not sure if I'm explaining it correctly.
The point is, if we make save function for the inventory will the sub resources (items) states be saved too?
Yes, this system will save all sub resources attached to another custom Resource.
If you don't want this behavior, you could pass in one of the flags defined in the docs :)
@@queblegamedevelopment4143 Another question please, Sensei. Does it include some bunch on properties from my item class, like if I include var locked = false, then I use a button to turn the property to true then save it. will it remain true?
I believe you'd need to export the variable in order to save its value to the resource file
How would you be able to save the players location as well? And would playerdata be where you put ur controls and such?
Player data would simply store any data you'd want to save to a file.
To save the players location, you'd have a player scene somewhere in your game with all the controls attached to it's own script.
Then, when you save the game, simply store the player's position vector to this file in any manor you'd like.
Upon loading, all you have to do is retrieve this information, then apply it to the player's position when they spawn in
@@queblegamedevelopment4143 so like @export var vector in the playerdata?
Yup!
@@queblegamedevelopment4143 so for the save ud wanna save EVERYTHING like npc locations and all that, would that be the same concept except with npcData? and same with everything else?
Yes, and if you want, u could just put all you data in on file inside dictionaries
If this video was a resource, I’d make it a sub resource of my player data
:O
I feel like I'm missing something with this when I try, did you add the PlayerData script to autoload or something??? Did I just miss that or something?
Or is this a innate behavior of the Resource class??
@@crey416 when you make your own class (in this case the custom resource he made is a class) you can access it globally just using it's name :)
Is the resource file editable outside of the game, ie could a player open up the save file and just tweak the health to 200? Does the resource tool have a way to encrypt the file to prevent player tampering?
Yes it is editable, but you can also encrypt it if you want with open_encrypted or open_encrypted_with_pass (you can read up on their functionality on the Godot docs in FileAccess)
You can also do this.
You can save them as .tres which makes it readable and editable in a text file
But you can use .res which makes it just data and unreadable in a text file.
Can I use this Method to make my own Modding Support System?
Yeah technically you could!
Thanks for the great video for me as an beginner!! Is there any way to encrypt the savedata since the tres file can be viewed as plain text? Thanks again for the tutorial.
Yeah of course!
You can checkout my latest video for a walkthrough on encrypting the save file :)
Just watched very helpful. Is that possible you could make another tutorial to show how to use both Json and custom resource together for like big amount of items/gears/quests/...etc? Thanks anyway.
@@queblegamedevelopment4143
Great explanation!! In our current project I am also at the point to Check for the best possibility in saving gamestate with the necessary information. I am currently using dict with json in ecrypted format. Is encryption somehow also working with your approach? I mean we cannot let the player of the Game just use notepad to edit its savefile😆
Thank you!
Yes, there is a way to encrypt the save resources, and it's actually pretty straightforward!
I do have a tutorial lined up to be recorded (which will cover this), but it will probably be a while before I have time to do so :/
I would suggest checking out these 2 links though:
kidscancode.org/godot_recipes/4.x/basics/file_io/index.html
docs.godotengine.org/en/stable/classes/class_fileaccess.html
I think the docs cover how to use the save/load encrypted methods briefly, but that's what you'll want to look at :)
@@queblegamedevelopment4143 thanks ! Looking forward to your Video :) thanks for the links
@@echtaGanxta Hey if you're still having trouble with this, I've just released a video on the topic :)
ruclips.net/video/mI4HfyBdV-k/видео.html
@@queblegamedevelopment4143 thanks man, will check this out :)
Keep it up.I follow you from iraq🇮🇶❤ and do more videos like that❤
I'll need to try this with a POCO for the sub-class I guess. If it can handle that properly then this will make Godot insanely good and likely my engine of choice.
Edit....
Wait a second... actually no that I think on you are using the .new() method meaning those are instances of the resource so say 1 apple is green and the other is red. Changing 1 wont change the other... Pretty cool, in Unity I'd go about converting SO data to POCO to avoid serialization issues...
Boss!
json is still secured
8:12
عاش يسطا
it is a bad idea to use resource files over json for save files, resource files is not safe, they can contain functions that can contain malicious code, you should only allow resources that you the developer have made and never allow any from user land to be loaded.
What really can i use the resources to make game i face any problems to publish
Typically you don't have to worry about this, but yes, if you're encouraging players to download workshop items or external files, you should probably look at encoding the files
@@queblegamedevelopment4143 So what's the alternative? json files are a mess to load and save. More a mess to attach the data to the correct spots. Unless you use the resource as a file manager that distributes the data where it needs to go. What if I have 50 enemies and a level that needs saving... There has to be a better way.
You should generally only be concerned about a potential security risk if the player will be downloading files from external sources (steam workshop or mods), but obviously this would be the user's fault if they're downloading files from a sketchy website or untrusted source.
In the case that users are downloading custom files though, you should look into encoding the save files.
@@queblegamedevelopment4143 I'm testing json files for holding static data like an item list, then assigning it internally to a resource. Then I can save the resource as part of my save. It's only a test game until I learn more so I'm all good. Hey, thanks so much for the reply. :) And the video.
resource files feel like C# static classes, once I got the jest of them.
Please don't do this. This is a massive potential security risk.
Thank you for pointing this out!
I'm trying to get around to making a video explaining when and when to not use this system, and also explain the obvious exploitation that can occur 👍
I don't see the issue as long as the player doesn't download random shit online?
@@proximacentauri1172Yeah, but I feel like "that's their own fault" only goes up to a point. Like, if a gun dealer sells a gun to an incompetent person, and then they shoot someone on the street because they weren't being careful, the dealer would get in trouble because they sold a gun to an incompetent person. Same deal here, the player makes a fatal mistake, and because the developer put all responsibility on them, they suffer disastrous consequences.
it's fair, maybe if your game includes a save system like this then you can put a big DISCLAIMER saying hey don't load random shit from online. if you do you oculd get viruses or whatever. @@pointyorb
I'm using this for a simple hour tracking app that I'm making on my PC in order to track how many hours I've done a specific activity for. in this case there is really no reason to encrypt the data because I'm never going to download someone else's "save" this way nor would anyone else. it's simply to store a couple of variables such as the amount of hours i've done the activity for and what the activity's name is
@@pointyorb Your comment caused me to go crazy. I think you should be held responsible for any craziness I commit from now on.