#Packedscene saving problem Godot 4.5.1

14 messages · Page 1 of 1 (latest)

sharp relic
#

I don't understand why the file wont load properly

    print("2dscenePacked: ", data.current_2d_scene)``` 
2dscenePacked: <PackedScene#-9223371825344409755>

ResourceSaver.save(data ,"user://save.tres")

func _load():
var path := "user://save.tres"
if FileAccess.file_exists(path):
var data = ResourceLoader.load("user://save.tres") as SceneData
print(data) ##<Resource#-9223371792310068520>
print("2dscene: ", data.current_2d_scene)``` 2dscene: <null>

#


var player_1_moral : int = 0

#var time : TimeHandlers
var current_2d_scene : PackedScene = null #Node2D
var current_3d_scene : PackedScene = null #Node3D
var current_gui_scene : PackedScene = null #Control
#

It may be because of dependencies Let me check

#

Packedscene saving problem Godot 4.5.1

#

4.0 May work for people

#

the save file:


[ext_resource type="Script" path="res://assets/singleton/scene_data.gd" id="1_dw8s2"]

[resource]
script = ExtResource("1_dw8s2")
#

it isn't a singleton, I forgot to move it to another folder

sharp relic
#

I tried saving other stuff to the resource, and loading it (numbers and a dictionary)

the number was default number from SceneData
the dictionary == {}

foggy iris
#

only export variables are serialised in resources when saving them

#

that's why the @export_storage annotaiton exists.

#

in case you want to save variables but not want them to be visible in the resource inspector like normal export variables.

sharp relic
#

thanks

foggy iris
# sharp relic thanks

i would kinda suggest you to instead of saving the whole packed scenes to instead just save the filepaths of them. then you could also just use JSON to save that data, which is generally the better choice.

foggy iris