0 votes

Calling ResourceSaver.save() doesn't save the values of any variables from my custom resource at all. How do I know this? because when trying to print a variable from the loaded resource, it returns null. And yes the variables do have a value before saving the resource.

Here is my custom resource script:

extends Resource
class_name GlobalSaver

const SAVE_PATH = "user://saved_settings.tres"

var bomb_plant_code
var bomb_defuse_code
var bomb_plant_time
var bomb_defuse_time
var random_code_plant_length
var random_code_defuse_length
var bomb_expload_time
var reset_plant_or_defuse_length

func save_to_disk() -> void:
    for v in Global.DEFAULT_VARS.keys():
        print('{0} : {1}'.format([v, get(v)]))

    ResourceSaver.save(SAVE_PATH, self)
    print(load(SAVE_PATH).bomb_plant_code)

func load_from_disk() -> Resource:
    if ResourceLoader.exists(SAVE_PATH):
        return load(SAVE_PATH)
    return null
Godot version 3.5.1
in Engine by (51 points)

1 Answer

+1 vote

I think they need to be export variables to be saved.

by (8,528 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.