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 /
avatar image
0
Question by Mansitos · Oct 17, 2017 at 11:33 PM · androidsaveloadsave datapermissions

Save&load 100% works on pc, but not on android!

Hi guys, I Just code my first save and load script for my first android app. It works fine, 0 errors on pc, but when I build the game and run it on android nothing is saved after saving. Maybe is something wrong in the code? Or maybe is something about android permissions? in fact in the smartphone "app" area, I can see that my app has 0 permissions, maybe it cant write/read files. Any suggestions? Thanks :D I will paste my code! (c sharp)

using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Runtime.Serialization.Formatters.Binary; using System.IO;

public class SaveLoad : MonoBehaviour {

 public static void Save(){

     BinaryFormatter binaryFormatter = new BinaryFormatter ();
     using (FileStream fs = new FileStream ("gamesave.bin", FileMode.Create, FileAccess.Write)) 
     {
         binaryFormatter.Serialize (fs, RecordCheck.recordvalue);    
         binaryFormatter.Serialize (fs, SoundController.muted);    
         Debug.Log ("SaveFileUpdated");
     }
 }

 public static void Load()
     {
         if (!File.Exists ("gamesave.bin")) {
             Debug.Log ("SaveFileNotFound");
             return;
         }
     if (LoadStarter.alreadyloaded == 1) {
         Debug.Log ("YouAlreadyLoadedTheSaveFile");
         return;
     }
     else 
     {
             BinaryFormatter binaryFormatter = new BinaryFormatter ();
             using (FileStream fs = new FileStream ("gamesave.bin", FileMode.Open, FileAccess.Read)) {
                 RecordCheck.recordvalue = (int)binaryFormatter.Deserialize (fs);
                 SoundController.muted = (int)binaryFormatter.Deserialize (fs);
                 Debug.Log ("SaveFileLoaded");
         }
     }
 }

}

Comment
Add comment · Show 10
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 Mansitos · Oct 18, 2017 at 09:15 AM 0
Share

Any help? I can't get out of it :(

avatar image Dorian01 Mansitos · Oct 18, 2017 at 09:42 AM 1
Share

I think you need save gamesave.bin with https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

avatar image unit_nick Dorian01 · Oct 18, 2017 at 09:56 AM 0
Share

Thats what I said about 7 hours ago, but he has ignored it

avatar image Mansitos Mansitos · Oct 18, 2017 at 10:31 AM 0
Share

Sorry I didnt see, I will try :) thanks

avatar image unit_nick Mansitos · Oct 18, 2017 at 10:39 AM 1
Share

np. while you can just use normal + to concatenate their is a built in function for combining paths. eg..

 public string fileName = "gamesave.bin";
 private string filePath;
 
 private void Start()
 {
     filePath = Path.Combine(Application.persistentDataPath, fileName);
 }
Show more comments
avatar image Mansitos · Oct 18, 2017 at 12:00 PM 0
Share

Thanks, when at home I will try. It is my first experience in unity so I'm a nooby :) but what about app permissions? It has no permission when I check it

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by unit_nick · Oct 18, 2017 at 02:36 AM

I'm not sure but shouldn't you be using a Unity path in your file path? https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

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

153 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

Related Questions

im getting a serialization exception eror in my load method 0 Answers

Dinamic name for data save 0 Answers

Where to save player progress for playstore app? 1 Answer

Save and Load in the build 0 Answers

Problem with saving and loading game timer 0 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