The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello everybody,
I have a small issue with the saving and loading of ressources… Here is exemple :

Class RessourceA :

extends Resource

class_name ResourceA

var data1 : int
var data2 : int
var data3 : int

Class RessourceB :

extends Resource

class_name ResourceB

var resource_a_preload = load("res://")
var resource_a_array : Array

func run():
    for i in range(10):
        var res =
        res.data1 = i + i
        res.data2 = i * i
        res.data3 = res.data1 + res.data2
        print("Data1 %d | Data2 %d | Data3 %d" % [res.data1, res.data2, res.data3])

Class Handler :

extends Control
var resource_b_preload = preload("res://")
func _on_SaveFSMButton_pressed():
    var result ="res://file.tres", resource_b_preload)
    if result != 0:
        print("Something goes wrong !")

File’s content :

[gd_resource type="GDScript" format=2]

script/source = "tool
extends Resource

class_name ResourceB

var resource_a_preload = load(\"res://\")
var resource_a_array : Array

func run():
    for i in range(10):
        var res =
        res.data1 = i + i
        res.data2 = i * i
        res.data3 = res.data1 + res.data2
        print(\"Data1 %d | Data2 %d | Data3 %d\" % [res.data1, res.data2, res.data3])

As you can see, my file has the source code but not the data stored in ResourceB.
What am I doing wrong when I'm saving the file ?
Thank you in advance

Godot version 3.2
in Engine by (81 points)
edited by

not super expert on the topic, but resourcebpreload seems to be the proloaded resource only.
does it work if you change it with

var result ="res://file.tres", res)


You're totally right... facepalm
I fixed it but know my file looks like that :

[gd_resource type="Resource" load_steps=2 format=2]

[ext_resource path="res://addons/TyFSM/Content/" type="Script" id=1]

script = ExtResource( 1 )

I tried to load my resource like this:

var resource = ResourceLoader.load("res://file.tres")

and like this :

var resource =
resource = ResourceLoader.load("res://file.tres")

The result of the print, in both case, is : 0

mmmm, i can see that you decleared the resource_a_array but never filled, so 0 should be correct.
did you forget about it or simply positionated in another part of the code?

What's wrong with me...
I add at the end of my run() method :


But the file is still the same

i think another error could be that you used, res) instead of, res)
I'm not 100% sure though, as i cant find any documentation on method

Sorry, it was a typo... I'm already using
I fixed my first message

does it work if you store less complex data?
like try adding 2 test variable in the resource_b

var test1=1
var test2=0
func run():

does the loader correctly shows the value 1 for test1 and value 2 for test2?

I tried but nothing changed...
I think that the issue is from the saving beceause the file is "empty".
There is some information about the resource but no data

on below tutorial, the guy uses
var res : Resource =load(path), instead of using the resourceloader.
Maybe try that?

if that doesnt work either, i think i have no more suggestion sorry :(

I had already follow this tutorial at the beginning of my quest.
But I noticed something that I didn't think was important at the time... All the saved data has the keyword "export".
I added it to my code and everything is working perfectly now!
Thank you for your help

1 Answer

+3 votes
Best answer

Just turning my last comment as an answer...
If someone has this problem, add the "export" keyword to all the data you want to save and it should work

by (81 points)

understood, so the engine only save the data of the export var in the resource?
good to know! i dont think this is mentioned in any docs

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.