#Telling the computer how to save variables

1 messages · Page 1 of 1 (latest)

primal quiver
#

so i have a custom save system that saved items. its not too much to worry about but all you need to know is that it saves variables such as ints, floats, bools, etc.. I also want to make an item shop where you can change cosmetics such as your skin, enemy skins and stuff similar to that. What is the best way to save this? Should I create a bool for each item? should I do an id system? this is my first time and the least amount of values i have to store the better but I also dont know exactly how I will do this so im just brainstorming now.

vestal hornet
#

Id systems usually provide a very solid approach for saving, especially with stuff like items. So I would probably go with that.

primal quiver
#

ive just never gone with this before

vestal hornet
#

I don't know of any tutorial implementing an ID system, sadly.
But the process should be pretty straightforward. Assuming that your items are stored as Scriptable Objects, you can simply generate guids for them using System.Guid.NewGuid().ToString() in OnValidate. Just be sure to check whether they already had one before.

primal quiver
#

what are guilds

narrow skiff
#

globally unique identifiers, and a builtin structure in NET

vestal hornet
#

GUIDs, not Guilds kekw

primal quiver
#

oh my bad haha

narrow skiff
#

there is a chance that guids are not unique, but it is really really low, in most cases, for your app, they will be unique

#

also, about OnValidate, make sure to only do that once if the guid reference is still empty.
guids are also not serializable by unity so you need to find a different way to store them, for example storing the string representation

primal quiver
#

ill look into it. do you guys mind if i keep this thread open so I can ask for some help

vestal hornet
#

I don't think anyone will delete forum posts, unless they violate some kind of rule. So no worries about the post getting closed.

narrow skiff
#

I actually wanted to add the suggestions solution from thread 2 into my library but I don't think I've done that yet

#

there are some caveats, like it is fine if you have scriptable objects with guid generations if you have unique assets, but it's harder if you need to have them with prefabs, because not only the prefab would need them, but especially the persistent prefab instances in the scenes, which need separate ones

vestal hornet
narrow skiff
#

there are also assets you could use for saving, like easy save

primal quiver
#

is there a tutorial specifically on using this kind of system. im not super new to unity but havent ever worked with this beofre

narrow skiff
#

I guess for their use case it works

vestal hornet
#

but still, imagine you make some kind of grid-based base building game and use this. and then you place one object at 2, 2 and one at -2, -2. have fun figuring out IDs

cosmic depot
#

System.Guid is 16 bytes, whereas string representation will be like.. 32 at least

vestal hornet
cosmic depot
#

it can't you're right, but it can serialize byte array

#

Only time you should ToString a guid is for human representation should the user ever need to see it

vestal hornet
#

Touché.
Didn't know Guid had ToByteArray tbh

cosmic depot
#

indeed

#

and then Guid constructor has an overload which accepts a byte array

#

so you can easily convert between them