How to Save and Load in Godot

Sdílet
Vložit
  • čas přidán 26. 08. 2024
  • Create a script inheriting from resource.
    Put any variables you want in the script, but only use built-in types.
    Only variables with the export tag will be saved.
    You can initialize the variables by overriding the _init() function.
    Give your resource script a class name at the top of the script.
    In a separate script, declare a variable using the resource class name as the type.
    Create the resource using the class name followed by .new().
    Save the resource using ResourceSaver.save(_var_name, "user://filename.res")
    Load the resource using _var_name = ResourceLoader.load("user://filename.res")
    Be sure to set the variables inside the resource before saving, and get their values after loading.
    Patreon: / tyanuziello
    Discord: / discord
    Udemy
    www.udemy.com/...
    www.udemy.com/...
    Skillshare
    www.skillshare...

Komentáře • 8

  • @cltran86
    @cltran86 Před měsícem +2

    Concise and to the point. More tutorials should strive for this

  • @GameTourist491
    @GameTourist491 Před měsícem +1

    subscribed, hope to see more content like this

  • @Dadax9398
    @Dadax9398 Před měsícem +1

    Really helpful video
    Also consise and clear, wich is perfect!

  • @skaruts
    @skaruts Před měsícem

    Nice video. You don't need the "_init" function for default values though. You can define the variables with values by default:
    *@export foo: int = 10*

    • @TYanuziello
      @TYanuziello  Před měsícem

      I know, just a habit for initializing more complex structures. Obviously most save files will contain more than just 1 integer.

  • @screaming_goat8778
    @screaming_goat8778 Před 27 dny +1

    is it possible to save arrays in godot?

    • @TYanuziello
      @TYanuziello  Před 26 dny

      Yes, any built-in type can be saved, including Arrays and Dictionaries.