How to Save and Load in Godot
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...
Concise and to the point. More tutorials should strive for this
subscribed, hope to see more content like this
Really helpful video
Also consise and clear, wich is perfect!
Glad it was helpful!
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*
I know, just a habit for initializing more complex structures. Obviously most save files will contain more than just 1 integer.
is it possible to save arrays in godot?
Yes, any built-in type can be saved, including Arrays and Dictionaries.