Save Files in Godot! (Custom Resource Tutorial)

Поделиться
HTML-код
  • Опубликовано: 2 янв 2025

Комментарии • 84

  • @queblegamedevelopment4143
    @queblegamedevelopment4143  Год назад +8

    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

  • @nemene8585
    @nemene8585 Год назад +82

    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

    • @thenopill
      @thenopill Год назад +7

      Thank you. I don't know that.

    • @dibaterman
      @dibaterman Год назад

      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.

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +8

      You should checkout my newest save load system (I go over how to fix this exploit) :)

    • @DEADEYESTUDIO
      @DEADEYESTUDIO 11 месяцев назад +2

      honestly if anyone is downloading random saves, then thats on them. gotta be safe on the internet

    • @nemene8585
      @nemene8585 11 месяцев назад +2

      @@DEADEYESTUDIO yup, i think this is just something to be aware of

  • @jonasan77
    @jonasan77 Год назад +2

    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

  • @dexlovesgames_dlg
    @dexlovesgames_dlg 15 дней назад

    this and the loading .json static data video... subscribed.

  • @CptNelson
    @CptNelson Год назад +2

    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.

  • @jaxterity
    @jaxterity Год назад +9

    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
      @hw2007 7 месяцев назад

      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?

    • @jaxterity
      @jaxterity 4 месяца назад

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

  • @fabiovie92
    @fabiovie92 Год назад +2

    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!

  • @bryansmith508
    @bryansmith508 Год назад +9

    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.

  • @anwaardev
    @anwaardev Год назад +1

    Great video, will definitely implement it on my game!

  • @GaryParkin
    @GaryParkin Год назад

    Thank you for all the help. Now I understand resource classes.

  • @victorbied1
    @victorbied1 7 месяцев назад

    Very nice and clean!

  • @johnmerriam7844
    @johnmerriam7844 2 месяца назад

    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

  • @itsjustkhoa6754
    @itsjustkhoa6754 Год назад +1

    Very helpful video, keep it up!

  • @simonsaysgray
    @simonsaysgray Год назад

    very useful video, thank you!

  • @chimingito
    @chimingito 2 месяца назад +1

    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

  • @Kio_Kurashi
    @Kio_Kurashi 11 месяцев назад +1

    "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: 😲

  • @thatdudeimaad
    @thatdudeimaad 4 месяца назад

    if i use resources to save, i have to move all my methods involving variables in main to the playerdata class, right?

  • @SaintTrinaLore
    @SaintTrinaLore Год назад

    Great video thank you!

  • @RedHedDes
    @RedHedDes Год назад

    Great video, thanks!

  • @SugarRushLab
    @SugarRushLab 4 месяца назад

    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

  • @SaintTrinaLore
    @SaintTrinaLore Год назад +2

    Any chance you could post an example "item lookup" Json file? I'm working to implement that next in a game I'm developing ❤

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

      Yeah ofc!
      Do u mean like an example line of code for accessing an item, or an example json file?

    • @SaintTrinaLore
      @SaintTrinaLore Год назад +1

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

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +2

      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!

  • @artfreak2074
    @artfreak2074 Год назад +2

    Nice one. What is the reason for duplicating the loaded player data?

    • @ameredude
      @ameredude Год назад +1

      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.

  • @AgriasOaks99
    @AgriasOaks99 Год назад +1

    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?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад

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

    • @AgriasOaks99
      @AgriasOaks99 Год назад +1

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

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад

      I believe you'd need to export the variable in order to save its value to the resource file

  • @armyofchickens6062
    @armyofchickens6062 Год назад +1

    How would you be able to save the players location as well? And would playerdata be where you put ur controls and such?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

      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

    • @armyofchickens6062
      @armyofchickens6062 Год назад

      @@queblegamedevelopment4143 so like @export var vector in the playerdata?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

      Yup!

    • @armyofchickens6062
      @armyofchickens6062 Год назад

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

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

      Yes, and if you want, u could just put all you data in on file inside dictionaries

  • @OctagonalSquare
    @OctagonalSquare 11 месяцев назад +1

    If this video was a resource, I’d make it a sub resource of my player data

  • @crey416
    @crey416 Год назад

    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?

    • @crey416
      @crey416 Год назад

      Or is this a innate behavior of the Resource class??

    • @bonsaipropaganda
      @bonsaipropaganda 9 месяцев назад

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

  • @RasperHelpdesk
    @RasperHelpdesk Год назад

    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?

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +2

      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)

    • @jaxterity
      @jaxterity Год назад

      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.

  • @FoxinessHD
    @FoxinessHD 6 месяцев назад

    Can I use this Method to make my own Modding Support System?

  • @lofinotion
    @lofinotion Год назад

    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.

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

      Yeah of course!
      You can checkout my latest video for a walkthrough on encrypting the save file :)

    • @lofinotion
      @lofinotion Год назад

      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

  • @echtaGanxta
    @echtaGanxta Год назад

    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😆

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +1

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

    • @echtaGanxta
      @echtaGanxta Год назад

      @@queblegamedevelopment4143 thanks ! Looking forward to your Video :) thanks for the links

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад

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

    • @echtaGanxta
      @echtaGanxta Год назад

      @@queblegamedevelopment4143 thanks man, will check this out :)

  • @ALIAli-di8ph
    @ALIAli-di8ph Год назад

    Keep it up.I follow you from iraq🇮🇶❤ and do more videos like that❤

  • @dibaterman
    @dibaterman Год назад

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

  • @highscore99999
    @highscore99999 Год назад +1

    Boss!

  • @m4y0ch33si3
    @m4y0ch33si3 11 месяцев назад

    json is still secured

  • @bitatara9575
    @bitatara9575 7 месяцев назад +1

    8:12

  • @M2N17
    @M2N17 5 месяцев назад

    عاش يسطا

  • @tonnypedersen5915
    @tonnypedersen5915 Год назад +10

    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.

    • @successspotu
      @successspotu Год назад

      What really can i use the resources to make game i face any problems to publish

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад +5

      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

    • @GaryParkin
      @GaryParkin Год назад +1

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

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад

      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.

    • @GaryParkin
      @GaryParkin Год назад

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

  • @cpuccino
    @cpuccino Год назад +3

    Please don't do this. This is a massive potential security risk.

    • @queblegamedevelopment4143
      @queblegamedevelopment4143  Год назад

      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 👍

    • @proximacentauri1172
      @proximacentauri1172 Год назад +3

      I don't see the issue as long as the player doesn't download random shit online?

    • @pointyorb
      @pointyorb Год назад

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

    • @bonsaipropaganda
      @bonsaipropaganda 9 месяцев назад

      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

    • @squarerootof2
      @squarerootof2 8 месяцев назад

      @@pointyorb Your comment caused me to go crazy. I think you should be held responsible for any craziness I commit from now on.