Godot Version
v4.4
Question
I made this function to save levels to the user directory before freeing them, and they load perfectly if they’ve been saved to disk once but not if they’ve been saved twice.
func save_level(root:level)->void:
for mover in root.movers:if mover.moving:
match mover.get_class():
"hinge" : mover.rotation = mover.folddest()
"slider": mover.position = mover.slidedest()
mover.move_stop()
for backvis in mover.backvises:print(backvis)
for droppable in root.punchouts:
if not(droppable.freeze or droppable.sleeping):
root.remove_child(droppable)
droppable.queue_free()
var scene := PackedScene.new()
scene.pack(root)
var anew_path := root.scene_file_path.begins_with("r")
var level_file := level_path[current_level].get_file()
var scene_path :=(
root.scene_file_path if not anew_path
else level_dir+level_file
)
#if not anew_path: DirAccess.open(level_dir).remove(level_file)# does nothing
ResourceSaver.save(scene,scene_path)
if anew_path: level_path[current_level] = scene_path
#else: scene.take_over_path(scene_path)# does nothing
If it’s been written to the path in user:// a second time it throws these and crashes
