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 MordazaH · Aug 20, 2020 at 05:37 PM · filewrite data

Save load file from PSVita

Hi all, Im making a PSVita game (not PSM) and I want to be able to save data in a file to later recover it (like to let player make custom track or anything that requires a lot of data), I have tried streamingassets folder and persistent data path, none seem to work, well I think streaming assets is read only or results shows that, I use streamreader and streamwriter for file access, could anyone please tell me how can I achieve this? I believe the problem might be the folder rather than the functions used, in the docs I cant find a good way to do this nor is told anywhere as far as i can see but of course it has to be written somewhere. Thanks a lot beforehand for any clue

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by highpockets · Aug 20, 2020 at 06:38 PM

This is what I use, mind you I have not worked with PSVita, but I believe it should work.


 using UnityEngine;
 using System;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;
 
 public static class StorageSystem
 {
     public static void SaveData<T>( T _data, string _fileName )
     {
         string _path = Application.persistentDataPath + _fileName;
         BinaryFormatter _formatter = new BinaryFormatter();
         FileStream _stream = new FileStream( _path, FileMode.Create );
 
         _formatter.Serialize( _stream, _data );
         _stream.Close();
     }
 
     public static TypeOfData LoadData()
     {
         string _path = Application.persistentDataPath + "/mydata.data";
             
         if( File.Exists( _path ) )
         {
             FileStream _stream = new FileStream( _path, FileMode.Open );
             BinaryFormatter _formatter = new BinaryFormatter();
 
             TypeOfData _data = _formatter.Deserialize( _stream ) as TypeOfData;
             _stream.Close();
 
             return _data;
         }
         else
         {
             Debug.LogError("File not found in " + _path);
             return null;
         }
     }
 }
 



EDIT: I forgot to mention that the data types that you save must be serializable. [System.Serializable] public class MyClass{}

Comment
Add comment · Show 3 · 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
avatar image MordazaH · Aug 21, 2020 at 12:57 AM 0
Share

Thanks for sharing your snippet, I think its quite clever strategy, however its not working for me in the Vita, in PC it works perfect. I tried also replacing the persistent data path with the Strea$$anonymous$$g assets folder and still didnt work (in pc it works with both folders), Im open to other ideas or folders that we could try to store file in, as said I have the feeling the biggest issue is the folder is not the right one, I heard player prefs work for PS$$anonymous$$ but well I didnt even try that as I want to store files and in player prefs as far as I know one can only store individual values or arrays isolated. As said feel free to suggest other methods or folders to achieve this =)

avatar image highpockets MordazaH · Aug 22, 2020 at 05:42 PM 0
Share

I noticed some others having issues with this. And there doesn’t seem to be a clear answer as far as I know. The reason that a persistent data path is not working is either because Unity has the wrong path, or you don’t have write permissions at that path on the console. $$anonymous$$y guess would be that it has to do with not having write permissions. Unfortunately I’m unfamiliar with PS Vita, so sorry I can’t be of more help.


I personally wouldn’t store sensitive data in PlayerPrefs. For example, on the iPhone, player prefs are stored in the app’s plist file and anyone can open that file and add whatever values they want to it. But I don’t have any idea where PlayerPrefs are stored on the Vita, so if you find that PlayerPrefs are a potential solution for you. You could turn the objects that you want to store into JSON strings and store them as strings in PlayerPrefs.SetString(keyName, value). Here is a little example of how you would store and retrieve an object:


 using UnityEngine;
 
 [System.Serializable]
 public class PlayerData
 {
     public int lives;
     public string username;
     public float health;
 }
 
 public class StorageSystem : $$anonymous$$onoBehaviour
 {
     public void SavePlayerData( PlayerData data )
     {
         if( data != null )
         {
             string json = JsonUtility.ToJson(data);
             PlayerPrefs.SetString( “PLAYER_DATA”, json );
         }
     }
     public PlayerData LoadPlayerData()
     {
         string json = PlayerPrefs.GetString( “PLAYER_DATA”, “No Player Data Found” );
         return JsonUtility.FromJson<PlayerData>( json );
     }
 }



That should work, but again, I would personally dig into how to get the write permissions for the persistent data path and store the file as binary as opposed to PlayPrefs, but I thought I would just show another option.

avatar image MordazaH highpockets · Aug 23, 2020 at 07:53 PM 0
Share

Thanks a lot for sharing this =), I had no idea we could convert a class into a json string and use it like this. Playerprefs works in the Vita so... your solution is perfect! =). I have tried several things and there is only one thing that apparently doesnt work but Im sure is because Im doing something wrong or the json is not supposed to support this, I tried making in my class different types of data and among the many things I tried I wanted arrays, they worked great, and also multidimensional arrays and these dont work, of course I can find a work around storing my data in single dimension array and just knowing where each row ends could do the trick, but just I wonder if there is a direct cleaner way to store the multidimensional array into the json, as far as I can read in the docs about ToJson, arrays wont convert unless these are in a class although they dont mention multidimension arrays there

avatar image
0

Answer by gregory34690 · Feb 21, 2021 at 12:19 AM

Hello! Did you find a solution? I'm not able to make a file in my psvita with unity too :( PlayerPrefs doesn't work too...

Comment
Add comment · Show 7 · 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
avatar image MordazaH · Feb 21, 2021 at 12:29 AM 1
Share

Hello, I think one can save some stuff using playerprefs but to create files is possible too, a friend found out the way in a PSVita development group we have at discord (if you want to join dont hesitate to ask). The method he found is something I havent tested myself but I can say if he says it works then it works, the way is to make any file you need in ux0:\data\ I cant remember entirely now if it was possible to make folder there too, but with that path you can make files so its a big step forward =).

avatar image gregory34690 MordazaH · Feb 21, 2021 at 12:51 AM 0
Share

Oh yes! It's works! Thanks, now i'm able to create files and folders in /ux0:/data/ You saved my life ahah

avatar image MordazaH gregory34690 · Feb 22, 2021 at 11:54 PM 0
Share

Great! =), Im glad I could help, so it worked even for new folders, its even better, I had that doubt, couldnt remember the exact way it worked, I hope you can make a great project and show it to the world, by the way if you have a youtube channel or place where you will showcase it Im eager to watch more about it =).

Show more comments
avatar image
0

Answer by Riviera71 · Feb 24, 2021 at 12:57 PM

Hi all,

For PlayerPrefs users I use "PlayerPrefs.Save()" method during gameover.

That's all!

When the game restart the new values are loaded.

I do'nt know where the PlayerPrefs are saved but it works!

I will investigate where they are stored.

Enjoy!

Comment
Add comment · Show 1 · 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
avatar image MordazaH · Mar 02, 2021 at 03:22 PM 0
Share

Thanks for sharing this =), yes right, it seems this way it works in almost every platform from what i tested, and as you said I have no idea where these are stored but works and thats what matters =). by the way since you are working for the Vita I wonder if you have a youtube channel or some site where you showcase your works, Im eager to see them =)

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

134 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

Related Questions

IOException: Sharing violation on path. Please Help! 2 Answers

How can I save data to a text/json file and read it back and then assign the values back to the variables ? 2 Answers

Create image-file from resources image 1 Answer

Console.WriteLine Redirect to file 0 Answers

Save XML file on desktop unity 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