Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Vuoripeikko · Jun 11, 2014 at 01:08 PM · androidsaveload

Loading and saving default files on Android

I'm having trouble trying to save default .xml files from the Resources folder into persistentDataPath.

When the game is booted up, a splash screen appears for a few seconds before fading to black and transferring the player to the main menu. While the splash screen is displayed, the game should check if the game has been started previously. If there are old saved files, the game won't copy default data over them.

Initialization.cs which is run at the start of the game

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class Initialization : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         //Checks if there isn't a save file
         if(!File.Exists (DataHandler.PlayerData())) {
             File.WriteAllText(DataHandler.PlayerData(), DataHandler.DefaultPlayerData());
         }
 
         if(!File.Exists (DataHandler.StrategyData())) {
             File.WriteAllText(DataHandler.StrategyData(), DataHandler.DefaultStrategyData());
         }
 
         if(!File.Exists (DataHandler.MunicipalData())) {
             File.WriteAllText(DataHandler.MunicipalData(), DataHandler.DefaultMunicipalData());
         }
         StartCoroutine(DisplaySplash ());
     }
 
     IEnumerator DisplaySplash () {
         yield return new WaitForSeconds (3);
         AutoFade.LoadLevel("menu_01" ,1,1,Color.black);
     }
 }


Part of the Datahandler.cs where the paths to the files are found

 using UnityEngine;
 using System.Collections;
 using System.Xml;
 
 public static class DataHandler {
     static TextAsset xmlAsset;
     static string xmlContent;
     //get current player data location as string
     static public string DefaultPlayerData() {
         xmlAsset = Resources.Load ("DefaultPlayerData.xml") as TextAsset;
         xmlContent = xmlAsset.text;
         return xmlContent;
     }
     //get current strategy data location as string
     static public string DefaultStrategyData() {
         xmlAsset = Resources.Load ("DefaultStrategyData.xml") as TextAsset;
         xmlContent = xmlAsset.text;
         return xmlContent;
     }
     //get current municipal data location as string
     static public string DefaultMunicipalData() {
         xmlAsset = Resources.Load ("DefaultMunicipalData.xml") as TextAsset;
         xmlContent = xmlAsset.text;
         return xmlContent;
     }
 
     //get current player data location as string
     static public string PlayerData() {
         return Application.persistentDataPath + "/" + "PlayerData" + ".xml";
     }
     //get current strategy data location as string
     static public string StrategyData() {
         return Application.persistentDataPath + "/" + "StrategyData" + ".xml";
     }
     //get current municipal data location as string
     static public string MunicipalData() {
         return Application.persistentDataPath + "/" + "MunicipalData" + ".xml";
     }
Comment
Add comment · Show 3
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 Landern · Jun 11, 2014 at 01:11 PM 0
Share

Do you get an error? If so what is it? Have you pulled the logs from your device to see if some exception is thrown, like an exception due to permissions?

avatar image Vuoripeikko · Jun 11, 2014 at 05:28 PM 0
Share

Running the game on Windows / Web Player works out fine. When run on Android, no error pops up - it simply stays stuck on the splash screen. I haven't played around with android developing though, so I haven't read into debugging yet. I thought it was an error in code.

avatar image Vuoripeikko · Jun 12, 2014 at 06:24 AM 0
Share

Here. It's mentioned that you can't debug via the USB cabel. I'm not sure if I can debug by wifi, don't you need a $$anonymous$$ac for that?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vuoripeikko · Jun 12, 2014 at 07:21 AM

Fixed the code. Apparently, Resources.Load doesn't need the .xml - ending, just Resources.Load("YourResource") as TextAsset.

Comment
Add comment · Share
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

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

22 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

Related Questions

PlayerPrefs don't load again after Android game closes for the first time. 1 Answer

Save and Load data from Local XML file won't work 1 Answer

Dinamic name for data save 0 Answers

Save and Load in the build 0 Answers

How can I save and read data on Android? 1 Answer


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