How and where to store game player data?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thomasedwards

I’ve just got started with Godot, and I’m trying to work out how to ask this question.

I’m building a game that’s heavy on user interfaces. The player doesn’t have a node. Ideally I’d like to use multiple scenes to make it more manageable.

There’s data in the game that I’d like to store and make available. Things like a name the player has chosen, and things they’ve created.

Looking through the docs, I can’t workout how other people are doing this. This isn’t config options, and should be part of the save file: so I don’t think ConfigFile is suitable. All the examples and tutorials I’ve found so far tie the data to the object it’s created in. From a non-Godot programming world, what I want is a class that has a single instance throughout the game and that I can get to from any other class.

I feel like I’m not searching for the right terms, as I’m obviously not the first person to need to save player data that’s not attached to a node.

:bust_in_silhouette: Reply From: kidscancode

You can store any arbitrary data you wish in a file. The example in File is pretty good:

Godot has built-in serialization, so the easiest is to use store_var() and get_var().

I’ve written a more detailed tutorial here:
http://godotrecipes.com/basics/file_io/

As for where, all data should be written to user://, as res:// is read-only when the project is exported.

Thanks! Does this method have high disk write/read usage?

thomasedwards | 2020-07-14 06:26

What do you mean? How often you read/write from the file is up to you.

kidscancode | 2020-07-14 06:29

Thank you very much, I post the new URL because I came across a 404: Saving/loading data :: Godot 3 Recipes

Ximun | 2023-06-04 12:42

:bust_in_silhouette: Reply From: rakkarage

to keep around while playing you can use godot version of singleton called auto load

to keep around locally can use file

but for data to really persist when user changes or loses device you can store in cloud using firebase or nakama

I feel like singleton was the missing word I was looking for!

thomasedwards | 2020-07-14 06:29