- Home /
PlayerPrefs base saving system (works in editor but not works on android)
Hello, I am preparing a mobile game that includes a shop. I save my shop state with a string, to save this string I use PlayerPrefs. My game works and saves everything correctly in the editor but when I build apk problem is starting the problem is; game saves shop state correctly when the game is running but when I quit the game my shop state turns to default (so every item that player bought are deleted). But the interesting thing is coins and high score do not go. I use PlayerPrefs.Save()
when needed I even try it in Update()
but nothing changes. I know there are similar question but I also tried them but nothing changes.
public string content = "hope";
public void Load(ShopItem item) // works when shop run.
{
int itemIndexInt = item.itemIndex;
int itemIsBoughtInt = item.isBought;
string contentPart = itemIndexInt.ToString() + itemIsBoughtInt.ToString();
content += contentPart + ITEM_SEPERATOR;
PlayerPrefs.SetString("content", content);
PlayerPrefs.Save();
}
public void Save(ShopItem item) //works when user buy or equip something (onclick)
{
string[] itemsArray = PlayerPrefs.GetString("content").Split(new[] { ITEM_SEPERATOR }, System.StringSplitOptions.None);
for(int i = 0; i < itemsArray.Length ; i++)
{
if (Equals(itemsArray[i], item.itemIndex.ToString() + item.isBought.ToString()))
{
itemsArray[i] = item.itemIndex.ToString() + item.isBought.ToString();
content = content.Replace(itemsArray[i] ,item.itemIndex.ToString() + "1");
item.isBought = 1;
PlayerPrefs.SetString("content", content);
PlayerPrefs.Save();
}
}
}
The string that I want to save is content
thanks all for helping.
Your answer
![](https://koobas.hobune.stream/wayback/20220612233533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Saving data 1 Answer
Updating my game on Play Store or App Store 0 Answers
Admob interstitial ad are slowing my game down 0 Answers
Porting simple game to android (Problem -> Controller) 0 Answers
Best FPS cap for mobile builds 1 Answer