Saving packed scenes by resource many times results in large file size

Godot Version

v4.5.1

Question

im making a game and i tried to implement a save system using resources. it saves a few variables, but also all of the coins as packed scenes with this script:

		var coins = get_tree().get_nodes_in_group("collectable")
		for collectable in coins:
			var cointhing = PackedScene.new()
			cointhing.pack(collectable)
			globalvariables.save_file_1.coins_i_think.append(cointhing)

saving a few times makes the save file very big, which makes the game lag. does anybody know how to fix it?

Why are you saving all the coins?

so each coin can be collected only once

Saving packed scenes is not the best way to implement a save system.

What you need to do is to store a variable in the coin scene that stores if has been collected. When instantiating the coin, just check the ‘collected’ variable related to that particular coin to determine if to spawn it or not.

2 Likes

oh, thats a good idea!

Here’s an article from Godot on Saving Games. You can also check out the lengthy write-up I did in this thread on how to implement the exact thing you’re looking for:

1 Like

its not really what i was looking for, since i’m doing the save system with resources. is there a way of saving each coin’s collected variable in one resource?

Sure.

  1. Create a Resource with a Dictionary where the key is a String, and the value is a bool.
  2. Create a function to add a coin’s info to the Resource.
  3. Create a function to retrieve the coin’s info.
  4. Put the Resource in a global autoload.
  5. In the coins, pass the UID and whether it’s been collected to the coin Resource whenever they are collected.
  6. Have the coins query with their UID when loading. If they are not found, they aren’t collected. If they are, they’re collected.
1 Like

ok so i didnt really get it and ended up saving the coins name in an array in the save file resource whenever its collected, and when the level is loaded, the coin checks if its name is there. it seems to work. thanks for help anyways!