Saving a PackedScene state with node array?

Godot Version 4.2

Question

How to save a PackedScene with a snap zone as an array. I added the original snap zone into a group called drop_zones but even when trying to add it to the packed scene the planters snap back to the purchase window.

removed link

and I have commented out the mains packing script.

removed link

Not sure what your question is.

If you are adding nodes in code and want them saved in the scene (in the editor), then you must set the owner, which I see you did, but it’s tricky. Try: set_owner(node.owner)

sorry, it’s early morning. I have a plant growing game with a purchase window that has a snap zone that spawns a planter when bought. If you move the planter to a different spot like one of the shelves, it will snap back to the window snap zone upon loading the packed scene.

I had tried packing the drop_zones group but it errored as it said it cant pack an’ array. So I tried just packing all of main to no success either.

It sounds like you are doing this snapping stuff while the game runs? If so, there’s no reason it would write/save the scene file. You have to manage all changes that happen and save/load them manually at runtime. (Use Resources for that.)

If that’s not what you mean, please work out how to ask your question in a better way.

Sorry for the late reply. So, say I have this after buying(instancing the pot scenes/red), and they are snapped down to a shelf spot/blue. I would be saving them and their position and the loading that?

Yes. The game state (values of certain variables) need to be saved intentionally by you (the dev).

Look into Resources. I made a short intro vid: https://www.youtube.com/watch?v=8ybDgDvAVNk

Also read the docs. Good luck!

This is my current save global, I have a bit of confusion on my part. I was trying to add a second dictionary reference, nested basically. I wasn’t thinking ahead and the pot is not part of globals.

extends Node

## SAVE DICTIONARY ##
func save_data_dictionary():
	var save_dict = {
		
		"Coins" : Globals.Coins,
		"Pot_Count" : Globals.potcount,
	}
	return save_dict
## SAVE DICTIONARY ##


func save_game():
	var saving_game = FileAccess.open("user://savegame.save", FileAccess.WRITE)
	var json_string = JSON.stringify(save_data_dictionary())
	saving_game.store_line(json_string)
	

func load_game():
	if not FileAccess.file_exists("user://savegame.save"):
		return

	var loading_game = FileAccess.open("user://savegame.save", FileAccess.READ)
	
	while loading_game.get_position() < loading_game.get_length():
		var json_string = loading_game.get_line()
		var json = JSON.new()
		var _parse_result = json.parse(json_string)
		var _node_data = json.get_data()
		
		Globals.Coins = _node_data["Coins"]
		Globals.potcount = _node_data["Pot_Count"]
		print(_node_data)
	
	
## Debug commands for save and load ##
func _input(event):
	if OS.is_debug_build() && event.is_action_pressed("Save_Debug"):
		SaveGlobal.save_game() # Debug only, press 9 to save
		print("DEBUG save")
		
	if OS.is_debug_build() && event.is_action_pressed("Load_Debug"):
		SaveGlobal.load_game() # Debug only, press 8 to load
		print("DEBUG load")
## Debug commands for save and load ##

Would I need a whole rewrite to include a way to pull a second one which I want to store. That being parent, file and pos x, pos y.

I did a main scene/pot version and was able to save the pot_dict. Though not being global I kinda walked into a corner and got lost as you can’t just call it from nothing and not a object ahead of time. it would end up wth a error that no such dictionary exist.

I am also thinking I need to step away from it for a little bit as I am getting frustrated and probably have the answer in the test version I was doing, I just can’t put it together.

I think you would benefit from some Youtube tuts on saving games. Just search for “godot save load game”

I have been looking at one and I think I may be getting closer. It says to make a new dictionary var in the global save and add it to the main dictionary.

Then in the other files script make a function for save and add saveglobal.(dictname) = var and saveglobal.save_game.