Loading custom resource errors

Godot Version

4.2.1

Question

Hi, I’ve been trying to save some data into a custom godot resource and I’m getting some weird errors? The code runs and the output is expected but I get ≈ 15 errors despite the code running?

This is my current resource class script (pretty basic, haven’t done much yet):

extends Resource
class_name data
@export var stat_array:=
@export var stat_dict:= {}
func set_array(array):
stat_array = array

and here’s my implementation of it after watching a couple tutorials:

func _ready():
var resource := data.new()
var save_file_path = “user://save/”; var save_file_name = “menu_array.tres”
DirAccess.make_dir_absolute(save_file_path)
resource.set_array(stats)
ResourceSaver.save(resource, save_file_path + save_file_name)
resource = ResourceLoader.load(save_file_path + save_file_name).duplicate(true)
print(resource.stat_array)

For some reason running “ResourceSaver.save(resource, save_file_path + save_file_name)” causes about 10 instances of this error:

E 0:00:03:0679 UI.gd:60 @ _ready(): Resource was not pre cached for the resource section, bug?
<C++ Error> Method/function failed. Returning: “null”
<C++ Source> scene/resources/resource_format_text.cpp:1853 @ _write_resource()
UI.gd:60 @ _ready()

and running “resource = ResourceLoader.load(save_file_path + save_file_name).duplicate(true)” gets 5 tween errors!?

E 0:00:03:0692 UI.gd:61 @ _ready(): Tween can’t be created directly. Use create_tween() method.
<C++ Error> Method/function failed.
<C++ Source> scene/animation/tween.cpp:499 @ Tween()
UI.gd:61 @ _ready()

Any help is greatly appreciated and thanks in advance!

If you save the file as “.res” (binary format) instead of “tres” does this issue still happen?

How does your stats array that you are trying to save look like?

Interesting, changing it to .res fixed the issue :thinking:. After a bit more testing, it seems that the error happens when trying to store a node on the .tres file with 2 no pre-cache errors and 1 tween error?
Anyways, thanks a lot for the help, I completely forgot about .res files! :+1:

This is where I found the .res workaround.

Might be of use to you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.