Scene not loading when saved to the same user:// path twice

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

After the first save copy the save-game file and compare it with the version that you get after the second save. My bet is that your loader isn’t instantiating something as it should be and that introduces a difference in the save game.
Any diff tool will be a great help for this.

I don’t remember how I fixed it, I just kept tweaking it and it went away
oh right nodes generated in script, owned, and saved in @export_storages refused to be called after saving and reloading, I had to make it generate new ones every time (don’t know if that’s related but it was around the same time)

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