How to Save and Load in Godot

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 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...

ความคิดเห็น • 10

  • @GameTourist491
    @GameTourist491 2 หลายเดือนก่อน +2

    subscribed, hope to see more content like this

  • @Dadax9398
    @Dadax9398 2 หลายเดือนก่อน +2

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

    • @TYanuziello
      @TYanuziello  หลายเดือนก่อน

      Glad it was helpful!

  • @cltran86
    @cltran86 2 หลายเดือนก่อน +2

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

  • @skaruts
    @skaruts หลายเดือนก่อน

    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  หลายเดือนก่อน

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

  • @nhatminh-pd4sl
    @nhatminh-pd4sl 7 วันที่ผ่านมา +1

    Can this save custom resources?

    • @TYanuziello
      @TYanuziello  7 วันที่ผ่านมา

      Yes, this is a custom resource that I created in the video.

  • @screaming_goat8778
    @screaming_goat8778 หลายเดือนก่อน +1

    is it possible to save arrays in godot?

    • @TYanuziello
      @TYanuziello  หลายเดือนก่อน

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