Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by piratecody · Aug 27, 2018 at 11:12 AM · androidloadingcrashing

Loading game data crashes on android

My game works in editor but crashes on Android. It appears to break when trying to load from a save file. Essentially, I save a bunch of dictionary values into Lists and then set the values of the dictionaries to the saved list values on load.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 
 public class Global {
 
     public static double masterClickCount; //The total number of clicks
     public static int adCookies; //
     public static Dictionary<string, int> multipliers = new Dictionary<string, int> (); //Key is the clicker/scene, value is the total multiplier
     public static Dictionary<string, double> multiplierUpgradePrices = new Dictionary<string, double>(); //Key is the clicker, value is the price of upgrading
     public static Dictionary<string, double> clickerPrices = new Dictionary<string, double> (); //Key is the clicker, value is the price to unlock the clicker
     public static Dictionary<string,Boolean> unlockedClickers = new Dictionary<string,Boolean>(); //Key is the clicker, value is whether or not its unlocked
     public static Dictionary<string, int> autoclickers = new Dictionary<string, int>(); //value is number of autoclickers in a given clicker
     public static Dictionary<string, double> autoclickerPrice = new Dictionary<string, double>(); //value is price of autoclickers
 
 
     public const int STARTING_MULTIPLIER = 1; 
     public const double STARTING_MULT_PRICE = 50;
     public const double STARTING_AUTO_PRICE = 75;
 
     //const values, each one is the name of a scene for the corresponding clicker
     public const string COOKIE = "Cookie";
     public const string ADCAP = "Adcap";
     public const string ANIME = "Anime";
     public const string CLICK = "Click";
     public const string PLANET = "Planet";
 
     public const int COOKIE_CLICK = 1;
     public const int ADCAP_CLICK = 2;
 
     public const string SAVE_FILE = "/clickception.dp";
 
     public List<string> keys;
 
 
     // Use this for initialization; sets all the initial values
     public static void InitStart () {
 
         if (File.Exists (Application.persistentDataPath + SAVE_FILE)) {
 
             LoadSave ();
 
         } else {
 
             //Starting values
             masterClickCount = 10000;
             adCookies = 0;
 
 
             //Initial multiplier level
             multipliers.Add (COOKIE, STARTING_MULTIPLIER);
             multipliers.Add (ADCAP, STARTING_MULTIPLIER);
             multipliers.Add (ANIME, STARTING_MULTIPLIER);
             multipliers.Add (CLICK, STARTING_MULTIPLIER);
             multipliers.Add (PLANET, STARTING_MULTIPLIER);
 
             //Initial multiplier upgrade prices
             multiplierUpgradePrices.Add (COOKIE, STARTING_MULT_PRICE);
             multiplierUpgradePrices.Add (ADCAP, STARTING_MULT_PRICE);
             multiplierUpgradePrices.Add (ANIME, STARTING_MULT_PRICE);
             multiplierUpgradePrices.Add (CLICK, STARTING_MULT_PRICE);
             multiplierUpgradePrices.Add (PLANET, STARTING_MULT_PRICE);
 
             //clicker unlock prices
             clickerPrices.Add(COOKIE, 0);
             clickerPrices.Add (ADCAP, 1);
             clickerPrices.Add (ANIME, 5);
             clickerPrices.Add (CLICK, 1);
             clickerPrices.Add (PLANET, 5);
 
             //Initial values for the unlocked clickers. Cookie starts unlocked
             unlockedClickers.Add (COOKIE, true);
             unlockedClickers.Add (ADCAP, false);
             unlockedClickers.Add (ANIME, false);
             unlockedClickers.Add (CLICK, false);
             unlockedClickers.Add (PLANET, false);
 
             //Initial values for autoclicker prices
             autoclickerPrice.Add (COOKIE, STARTING_AUTO_PRICE);
             autoclickerPrice.Add (ADCAP, STARTING_AUTO_PRICE);
             autoclickerPrice.Add (ANIME, STARTING_AUTO_PRICE);
             autoclickerPrice.Add (CLICK, STARTING_AUTO_PRICE);
             autoclickerPrice.Add (PLANET, STARTING_AUTO_PRICE);
 
             //Intialize autoclicker dictionary
             autoclickers.Add (COOKIE, 0);
             autoclickers.Add (ADCAP, 0);
             autoclickers.Add (ANIME, 0);
             autoclickers.Add (CLICK, 0);
             autoclickers.Add (PLANET, 0);
         }
 
         Debug.Log (Application.persistentDataPath.ToString ());
 
 
 
 
     }
 
 
     public static void SaveGame(){
         Debug.Log ("Saving");
         BinaryFormatter bf = new BinaryFormatter ();
         FileStream file = File.Create (Application.persistentDataPath + SAVE_FILE);
         PlayerData data = new PlayerData ();
 
         data.masterClickCount = masterClickCount;
 
         foreach (var kvp in multipliers) {
 
             data.keys.Add (kvp.Key); 
             data.multipliers.Add (kvp.Value);
             data.multiplierUpgradePrices.Add (multiplierUpgradePrices [kvp.Key]);
             data.unlockedClickers.Add (unlockedClickers [kvp.Key]);
             data.autoclickers.Add (autoclickers [kvp.Key]);
             data.autoclickerPrice.Add (autoclickerPrice [kvp.Key]);
             data.clickerPrices.Add (clickerPrices [kvp.Key]);
         }
 
         bf.Serialize (file, data);
         file.Close ();
         data = null;
     }
 
     public static void LoadSave(){
         Debug.Log ("Loading Save");
         if (File.Exists (Application.persistentDataPath + SAVE_FILE)) {
             BinaryFormatter bf = new BinaryFormatter ();
             FileStream file = File.Open (Application.persistentDataPath + SAVE_FILE, FileMode.Open);
             PlayerData data = (PlayerData) bf.Deserialize (file);
             file.Close ();
 
             masterClickCount = data.masterClickCount;
 
 //            foreach (string key in data.keys) {
 //                int counter = 0; 
 //                multipliers [key] = data.multipliers [counter];
 //                multiplierUpgradePrices [key] = data.multiplierUpgradePrices [counter];
 //                unlockedClickers [key] = data.unlockedClickers [counter];
 //                autoclickers [key] = data.autoclickers [counter];
 //                autoclickerPrice [key] = data.autoclickerPrice [counter];
 //                counter++;
 //            }
 
             for (int i = 0; i < data.keys.Count; i++) {
                 string key = data.keys [i];
                 multipliers [key] = data.multipliers [i];
                 multiplierUpgradePrices [key] = data.multiplierUpgradePrices [i];
                 unlockedClickers [key] = data.unlockedClickers [i];
                 autoclickers [key] = data.autoclickers [i];
                 autoclickerPrice [key] = data.autoclickerPrice [i];
                 clickerPrices [key] = data.clickerPrices [i];
                 Debug.Log ("Loading: " + key);
             }
 
 
         }
     }
     
 
         
 }
 
 [Serializable]
 class PlayerData{
     public double masterClickCount;
     public List<string> keys = new List<string>();
     public List<int> multipliers = new List<int> (); //Key is the clicker/scene, value is the total multiplier
     public List<double> multiplierUpgradePrices = new List<double>(); //Key is the clicker, value is the price of upgrading
     public List<double> clickerPrices = new List<double> (); //Key is the clicker, value is the price to unlock the clicker
     public List<Boolean> unlockedClickers = new List<Boolean>(); //Key is the clicker, value is whether or not its unlocked
     public List<int> autoclickers = new List<int>(); //value is number of autoclickers in a given clicker
     public List<double> autoclickerPrice = new List<double>(); //value is price of autoclickers
 
 }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NoDumbQuestion · Aug 28, 2018 at 04:14 AM 0
Share

you need to use debug on android to get extract error. There is nothing wrong with script above.

https://answers.unity.com/questions/1320966/android-debug-usb.html

$$anonymous$$ight be serialize problem. Wipe data on android might solve it.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

269 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android App Crashes Randomly 0 Answers

My game randomly crashes on some devices why ? and how do i fix ? 1 Answer

Android app load delay after quitting application 0 Answers

Unity 5.4.0b11. Crashes on startup at Android 4.2.2 (target 17) 1 Answer

App Crash on Android 11 Devices 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges