![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Godont |
I have a Singleton
called Inventory whose job is to immediately save changes to the player’s inventory, such as when the player picks up some coins. Save data for my game uses the Godot SQLite plugin.
Initially I found that immediately saving to the database would cause a small chug in the game’s framerate each time, so I put the save code into a thread:
func update_inventory(new_item : Dictionary):
var thread = Thread.new()
thread.start(self,"_update_inventory_threaded",new_item,2)
func _update_inventory_threaded(new_item : Dictionary):
Database.insert_data(new_item,Database.inventory_tbl_name)
However, this did not seem to remove the lag, and in fact this occasionally causes the game to hard crash (i.e. the game just closes).
Is there some other way to have instant saving without this lag? I want the player to be able to close the game at any time and still have all their progress saved.