- Home /
Its possible to save A list of material?
Hi i am trying to save with playerprefs a list of material added in play. But seems there is no way to do it.Any suggestion?
Answer by yashetv · Nov 11, 2019 at 02:26 PM
You can make array of Materials, and save it index of Material you need :)
thanks,but i don't know in code exactly,because material are added in play in this list in play with a loot system because i have 30+ material,can you show me an example?
What exactly do you mean by save? Serialization? Do you want the actual materials saved to disk or do you want a reference to a certain material? By default you can only use float, int, and string with PlayerPrefs so your direct answer would be "no." Other have suggested using PlayerPrefs as an index but this wouldn't be saving/serializing materials, just 'bookmarking' a certain point.
Okay so make simple schemat:
Script A has information about "Do player has a $$anonymous$$aterial", if yes then we save index of it. Example:
$$anonymous$$aterial[0] = ... $$anonymous$$aterial[1] = ... $$anonymous$$aterial[2] = ...
I don't know how you giving "$$anonymous$$aterial" to player but in this function you have to save this number (index). Lets say he got $$anonymous$$aterial number 1, so you save it by:
PlayerPrefSetInt("$$anonymous$$aterial", index$$anonymous$$aterial)
And at the start of your game you can just write:
PlayerPrefGetInt("$$anonymous$$aterial")
Tip: In the name of PlayerPref I use something like this:
PlayerPrefsSetInt("$$anonymous$$aterial[" + i + "]", index$$anonymous$$aterial);
So I don't have make name of each $$anonymous$$aterial.
Answer by AconitumNapellum · Nov 11, 2019 at 02:20 PM
Have playerprefs saves indexes of an array so at runtime you can get your playerprefs integers and you will know that you need material 5, 19, and 30 for example.