Im curious what ways there are to save variables between play sessions, i know you can use the saved variables tab of VS but it likes to delete itself when the VS package has updates or something, and im unsure if using a big dictionary is the way to do it (see image).
Also the only way i know to back it up in case it is all deleted by magic is either version control or screenshotting it all and manually writing it back in, which is less than optimal x_x
#Better way to save variables between sessions ?
1 messages · Page 1 of 1 (latest)
I think Saved Variables is the Only built in way to Save Variables. You will have to learn how to create your own Save System where you write and read the data from files(It's not complicated) or Maybe you can use PlayerPrefs if it's simple data like : Int, Float, Bool and String
i was gonna say theres no playerprefs nodes but i forgot i could add it in the node library, ill try that, thank you
You're welcome. Just lemme know if you need help with anything
Okay i may need help with it ^^"
Saving to playerprefs is nice and easy but it doesnt save if there is an update to the game, so i wanna save it in a text file but i have no idea how to serialise to json or something like that in visual scripting, im pretty lost, i guess i got the file stream nodes but its to write bytes directly to files, not really helping-
I dont know how to translate the C# tutorials i watched to VS, what should i do?
Send me the link to the tutorial you are watching I will try and convert the Script to the Graph for you
gimmie a sec
well i have this one but its binary not json
the json tutorials are all very different for some reason
https://youtu.be/XOjd_qU2Ido
a json one too if that helps
https://youtu.be/0KDU_SzrCkA
Here's everything you need to know about saving game data in Unity!
► Go to https://expressvpn.com/brackeys , to take back your Internet
privacy TODAY and find out how you can get 3 months free.
● Easy Save: https://bit.ly/2BzgdXb
❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU
················...
In this video i will teach you how to easily save any data into json file. This way you can save score, player position, enemy count and everything else you would need to save in your game! With this system it is very easy to add new variables you want to save and then to load them.
👍 Like and 🔔Subscribe for More Unity and C# Tutorials ht...
What values do you want to save?
The ones in this picture?
no its an example, ill add and change stuff anyways later but it should all be strings floats or bool (or ints if bools dont work)
does it have to be known beforehand ? or can is it like a big dictionnary where you get whatever key you need ?
Ok so basically a string key, with a String, Float, Bool or Int value?
Ok so dictionary saving is a bit more complicated so i created it in C# then you can just add the nodes to the graph by adding SaveSystem to the TypeOptions, also you should only use the new SaveSystem once you should not have more than one for each file so you should not have more than one save system that saves to save.json, and you can store it in a app variable for easy access
Is this fine?
this is PERFECT
Cool, I will send the file over in a sec
i feel like i have to pay you xd
thank you so much
So I made a quick change when you input the file name into the new SaveSystem/Create SaveSystem node dont add .json it automatically does that.
Also you will have to trigger the SaveSystem.Save node once you are done editing the values.
the new SaveSystem node already loads the file but you can also trigger SaveSystem.Load manually if you end up needing it
Just add the script to your project once it reloads add the Save system type to the type options
You're welcome just let me know if it's not working correctly
sorry for the wait awawa
it seems to work all good,~~ but i cant find the json anywhere-?~~
nevermind im an idiot i forgot to put the save node
thank you for putting a default value input i forgot to ask that, its great
You're welcome
so people use a aot list and save variable?
Hm, actually yeah in UVS that might have tripped me a little too. In C# we make classes serializable and from there just create json, csv, xml, binary, ini or whatever file type we want.
But in UVS without having serializable classes i definitely would have gotten confused
any visual scripting tutorial on saving progress and loading it?
Not that ive found, all the visual scripting tutorials on saved variables use the built in saved variables, thats why i made this thread cuz i couldnt find a better way
i meann, it works, but it gets tiedeous if you have a lot of variables or if they decide to spontaneously delete themselves
Also they are saved in Playerprefs so using Playerprefs as a way of saving variables is pretty much doing the same thing as using the regular saved variables
This .json solution is excellent, what great help. Saved (Playerprefs) is something I steered away from as soon as I identified I needed files for say Steam Cloud, or even multiple save files for breaking up data
I ended up following this creators work, and still use their save/load nodes
https://youtu.be/xFFDJLbIanw?si=T4ZVy8aRqobph7SH&t=192
We have created two new nodes or unit that you can use in your games.
Download here: https://smart-penguins.itch.io/spuc-unity-in-easy-mode
Request for Units here: https://smartpenguins.io/request-unit
Support this Channel: https://www.patreon.com/SmartPenguins
Discord: https://discord.gg/FPPJf5r
Facebook: https://www.facebook.com/SmartPeng...
looks very similar to what is above from X7. I feel like his save nodes were provided in a demo file (I didn't purchase his whole bundle)
One issue I did have, is saving INT - the output when I loaded the .json data, INT's would be in LONG format, so I had to make a little node to converts long to int. Unsure if this is a .json utility thing, or the SmartPenguins nodes above
it seems okay but it says i can only get a boolean,int,float or a string?
you can save most things with just those i think
position is just three floats, images can be encoded into very long strings, this kinda stuff
there's probably ways to turn arrays and lists into those too, i dunno
well no im an idiot, you can just save the individual elements of lists directly, because json is basically a big list/dictionary
bool, int, float or string are normal
with save files you have to think in much more abstract terms sometimes
but arrays already serialize to save formats
sometimes you even omit bool as a data type, using 0/1 instead
i typically save to either binary, json or xml. tbh.... aside from string, int, float, what else is there to save?
Classes are just collections of many ints, floats and strings.
and when you have objects within objects within objects, binary, xml or json formats just nest them as such.
There is a rule with serialization in unity though where you cant nest past a depth of.... i forget, 7?
what you cant save so easily is say.... asset/object references, like telling the game to remember specific children nested in their hierarchy.
Instead you have to have an index or id of some kind for that object and save that
then when you load you re-spawn objects as needed and reorganize hierarchies as shown in your data