How to Create SAVE & LOAD in Godot 4

Поділитися
Вставка
  • Опубліковано 23 чер 2024
  • In this video I go over how to implement a saving and loading system step by step in Godot 4. Saving and loading Data in your game is so important and so I explain exactly how it works so you have an understanding of what is going on when adding the system to your own Godot games. We will create a small example world and learn to save the players stats in a resource script, and then learn to reload them when we want to load the data back. Follow along with me and learn all there is to know about saving and loading in Godot 4.
    Link to Download Project on Itch.io: devworm.itch.io/save-and-load...
    Chapters:
    0:00 Intro
    0:33 Existing Project Info
    2:38 Download Save & Load Demo
    3:00 Save & Load Tutorial (step by step)
    18:54 How Save & Load Works
    20:17 Outro
    Thank you so much for watching, I really hope this video helped.
    if you did enjoy or this video was helpful then all I ask is if you could please subscribe to help out the channel. It means so much and I love your feedback in the comments. I’ll look forward to getting back to you soon! Again thanks so much and I would love to see you again!
    These Tutorials take a lot of time to create and I’m working on becoming a better Teacher and learning how to explain Godot things in a better way, if you’d like to support this journey to expand knowledge and help other game dev’s learn to create their own games then please.. Become a Member! It would mean the world and you’ll help me out so much! Thank you!
    have a great rest of your day and of course be safe :)
    - thanks DevWorm

КОМЕНТАРІ • 68

  • @tiagogarcia4900
    @tiagogarcia4900 5 місяців тому +35

    Hmmm I'll be saving this for later

    • @Memose2
      @Memose2 5 місяців тому +8

      Best comment I read so far

  • @firewolf11567
    @firewolf11567 5 місяців тому +10

    I came across your older save and load tutorial through the algorithm, then decided to look at your channel and saw you uploaded this 4 days ago! I recommend adding a pinned comment to your older tutorial linking to this one! Great job, and thank you!

    • @dev-worm
      @dev-worm  5 місяців тому +5

      youre right, thanks for reminding me! glad it was able to help!

  • @4U4U7
    @4U4U7 3 місяці тому +1

    Hi DevWorm! Just want to thank you so much, I have had troubles saving persistent data and just could not get it to work but I have solved it with your help! Keep well and keep up the good work.

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

      so glad to hear!! thank you so much!

  • @lucasmence
    @lucasmence 5 місяців тому +5

    I don't use godot yet, but I love to watch your videos about game dev, keep it up! Cheers!

    • @dev-worm
      @dev-worm  5 місяців тому +2

      I appreciate that!

  • @Kirbo-The-Dirbo
    @Kirbo-The-Dirbo 5 місяців тому

    I needed this so bad. Thanks

  • @SollyVlogs
    @SollyVlogs 4 місяці тому +1

    Thank you for the tutorial, super helpful :) !

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

      so happy to hear

  • @jasonwilliams8730
    @jasonwilliams8730 5 місяців тому

    Epic tuts!

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

    Cool guide for small games! But somewhat falls apart at scale.
    You'd need to create a centralized save/load structure with an inheritance paradigm instead of this coupled strategy.
    Also, saving directly as a .tres leaves the save file really vulnerable to security risks (injecting code, changing values). You can use Safe Resource Loader from the asset library to load a Resource more securely.

  • @PerfectUbaid
    @PerfectUbaid 5 місяців тому +1

    Hi man very interesting video

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

    You saved me a lot of time.

    • @dev-worm
      @dev-worm  3 дні тому +1

      so happy to hear!!

  • @cheapgrams2955
    @cheapgrams2955 5 місяців тому +4

    Hey Dev! Since I’m early I want to use my newfound comment powers to request an inventory system!! I feel like you could explain one in a simple and replicable way! Much love and thank you for the dope tutorials!

    • @thesomeone2nd
      @thesomeone2nd 5 місяців тому +1

      He already has 2 videos for that go check them out.

    • @dev-worm
      @dev-worm  5 місяців тому +1

      Just uploaded a really simple and for sure easily replicable 2 part tutorial series not long ago, I hope that is able to help

    • @cheapgrams2955
      @cheapgrams2955 5 місяців тому

      Ah yes I see, excuse my ignorance. Just excited to learn I guess lol shoulda looked deeper!

  • @MultiLeandrini
    @MultiLeandrini 5 місяців тому +1

    This exactly what I wanted/needed/was looking for. What is this timing? thanks

  • @WunderChilld
    @WunderChilld 5 місяців тому

    Thanks for the videos brother, could you bring a video explaining how to enter/use some type of vehicle? whether horse, car, etc.

  • @HippocritterXD
    @HippocritterXD 5 місяців тому

    this is a great video thanks for making it. i was wondering are you gonna continue with the survival game series?

    • @dev-worm
      @dev-worm  5 місяців тому

      any ideas for what could be next??

    • @gamer20_
      @gamer20_ 5 місяців тому

      maybe add this saving and loading
      @@dev-worm

    • @HippocritterXD
      @HippocritterXD 5 місяців тому

      @@dev-worm maybe a boss with a few mechanics

    • @HippocritterXD
      @HippocritterXD 5 місяців тому

      @@dev-worm or a level up system

  • @alli-gator-forest
    @alli-gator-forest 4 місяці тому

    Thank you for this amazing video!
    Personally, I wanted to load my Resource using the _ready() function, so I changed the load_data() function to add the following if statement:
    if ( ResourceLoader.exists( save_file_path + save_file_name ) ):
    playerData = ResourceLoader.load( save_file_path + save_file_name ):
    This ensures it won't try to load a file that doesn't exist on the very first time running the line of code, allowing you to call the load function before you make a save.

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

      ah yes!! thanks for pointing that out!!

    • @PraxVC
      @PraxVC 4 місяці тому

      mine spontaneously stopped working and this fixed it thank you

  • @reesekelly2388
    @reesekelly2388 5 місяців тому +2

    Great video. I really like the idea of using resources to save however there are a lot of people who are saying that if a player downloads files for your game it can breach their security. Is there a work-around for this? I also want to implement multiple saving slots so maybe I should just use JSON... even though it's a lot less intuitive.

    • @reesekelly2388
      @reesekelly2388 4 місяці тому

      Update: I got everything to work using JSON except the player inventory which is a resource. I think I am going to have to revert to the version of my game I had a month ago and implement a resource system instead of JSON. I have tried so many different methods. I would love to see @DevWorm's solution to saving an inventory because my inventory system is pretty similar to the one in his other video. It would help greatly Thanks!

  • @ROSACEPONY
    @ROSACEPONY 3 місяці тому

    Can you make a tutorial on how to make a character selection screen that also include a character creator and being able to save our character in a slot/list? (this definitely not for my game i swear😁)
    On a serious note, it could benefits a ton of gamedev as it's very common in RPG to have a character creator+selection screen.

  • @adrianvazquez8686
    @adrianvazquez8686 5 місяців тому

    Hey!! Would you make a tutorial on how to make a good menu and UI?? It'll be really helpful!!

  • @F_Du_Sea
    @F_Du_Sea 3 місяці тому +3

    Is there no easier way to do this? This seems really convoluted, and the tutorial itself doesn't help either. You have functions change_heath and UpdatePos (I'd stick to one naming convention, by the way) which have nothing to do with actually loading and saving. My point is that the code you write should be portable. Anyways, isn't there a way to do something like this?:
    # World Data
    with open("saves/save.json") as saveFile:
    data = json.load(saveFile)
    # Use Case
    if keys[pygame.K_e]:
    for chest in data["chests"]:
    if data["player"]["x"] == chest["x"] and data["player"]["y"] == chest["y"]:
    chest["open"] = True
    # Another Use Case
    xCamera = data["player"]["x"] - (xMax // tileSize) // 2
    yCamera = data["player"]["y"] - (yMax // tileSize) // 2
    In this code, the loading & saving are clearly displayed, and there is a use case. In this tutorial I can barley tell the two apart. Another criticism I have is the length of the video. There is absolutely no way you need 20 minutes to explain a concept as easy as literally opening a file, then reading & writing from it. You made a tutorial on how to make your game, not how to save and load files.

  • @leandroverse
    @leandroverse 4 місяці тому +1

    Why changing the resource in every frame? Couldn't it be changed when saving, like calling UpdatePos inside save() before ResourcerSaver?

  • @HoberMallow-tg3ph
    @HoberMallow-tg3ph 2 місяці тому +1

    Can you explain using .duplicate(true)?

  • @wellplayedggwp295
    @wellplayedggwp295 5 місяців тому

    I make resource of each collebtible items and export them to external resource file, and There is dynamic var inside resource which is amount(default is 0), but whenever i tried to make changes and load it, its always reset to its default var, is it Only saving the reference? Or I should not export each item and define them inside the code instead?

    • @dev-worm
      @dev-worm  5 місяців тому +1

      export each item and when changing the var make sure to do so in the external resource file

  • @uiet6527
    @uiet6527 4 місяці тому

    I'm making a 2d game using your all tutorials but I'm stuck with save and auto load when i exit and enter the game and i can't understand how the save and autoload works !
    Can you make a simple auto save and load video for simple game please

  • @MrStarlightt
    @MrStarlightt 5 місяців тому

    so does this save the game when i close the game, like will the player be in the saved position next time i open the game or is this a save system for a running game only?

    • @dev-worm
      @dev-worm  5 місяців тому +1

      yes if you save the data then close the game it will still keep that data saved for when you open the game back up

  • @Manimanocas
    @Manimanocas День тому

    Im sorry for commenting but do you think this is a good way of storing health, acquired skills etc across scenes?

  • @asd1-so5sl
    @asd1-so5sl 2 місяці тому

    What if I want to change the translated language?
    I've already done it so that when you click the buttons, the language of the game changes, but I want to save it.
    So when I reopen the game, if i had set the game to french, it opens in french. If I change it again to English, close it, and open it again, it should be in English.
    While I understand that it has the same method, I don't understand the coding part of it.
    I need a youtube tutorial on it please. can't find one.

  • @GameLog0
    @GameLog0 4 місяці тому

    I am a bit confused. I was planning on using this as a guide for a save/load system, but how would I reset the save file if i want to start over?

    • @PraxVC
      @PraxVC 3 місяці тому

      thats what im trying to figure out i accidentally put my player in a void ;-;

  • @uiet6527
    @uiet6527 4 місяці тому

    In future video can you make this video for clear explanation for beginners like me

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

      what arnt you understanding? maybe I could clear it up for you!

  • @Whhatt
    @Whhatt 5 місяців тому

    Can you please make a tutorial on deceleration on a 2d platformer
    Good vid btw

    • @dev-worm
      @dev-worm  5 місяців тому +1

      working on it!!

  • @fulla1
    @fulla1 5 місяців тому

    This resource file is only temporary, right? I mean if you restart the game it will always start with the same location and health.
    In other words: is this adaptable to have e.g. EXP, current level, ... saved permantently and load it on the next start of the game?

    • @dev-worm
      @dev-worm  5 місяців тому

      no its not temporary, it saves into that folder and file we created as variables. so if you close the game and come back then it will keep the saved data

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

    TYSM

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

      glad it helped!!

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

    I'm getting a "cannot call method 'duplicate' on a null value, not sure what to do, it saves fine, just doesn't load

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

      Nevermind, I forgot to make the save file .tres

  • @planktime
    @planktime 5 місяців тому

    HELLO!

    • @dev-worm
      @dev-worm  5 місяців тому

      HELLO!

    • @planktime
      @planktime 5 місяців тому

      @@dev-worm Thanks for coming through on that.... My GF is now saying hello the same way.

  • @tonnypedersen5915
    @tonnypedersen5915 5 місяців тому +2

    using resource files for save game system is a bad idea, they are not safe for use in user land, they are perfect for actual resources in the game and nothing else, for save game use a text based system or a actual database like SQLite or similar, it is also a good idea to encrypt the save file to prevent cheating.

  • @jeremiahaemile2008
    @jeremiahaemile2008 5 місяців тому

    thanks man
    i will watch it in my a vaction
    and ya i am jeremiah but i change my profile picture

    • @dev-worm
      @dev-worm  5 місяців тому +1

      thanks jeremiah so happy to see you brother!

  • @MochiRosu
    @MochiRosu 5 місяців тому

    MCSQUIRMY!!