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 goodgamershow · Jun 06, 2021 at 11:42 AM · unity 2djsondata storagestreamingassets

Unity doesn't see files inside StreamingAssets folder

So I'm trying to implement shop system to my game and I decided to use Json to store data about what skins has player already bought. I'm using the code below to Load & Save data into my .json file called "file.json":

 public class gameDataSaver : MonoBehaviour
 {
     public Skins skins;
     public void LoadData(){
         skins = JsonUtility.FromJson<Skins>(File.ReadAllText(Application.streamingAssetsPath + "/file.json"));
     }
     public void SaveData(){
         File.WriteAllText(Application.streamingAssetsPath + "/file.json", JsonUtility.ToJson(skins));
     }
     [System.Serializable]
     public class Skins{
         public bool[] isPurchased;
     }
 }

To use Json I created "StreamingAssets" in my project assets and then created a file called "file.json". When running the app, Unity gives me an error: fileNotFoundException: Could not find file "C:\Users\user\TouchFollower\Assets\StreamingAssets\file.json" I tried to check, if Unity sees the file by using the code below:

 private string path;
 private string jsonFileName = "file.json";
 
 private void Start() {
         path = Path.Combine(Application.streamingAssetsPath, jsonFileName);
        
         Debug.Log("Path of streamingAssets: " + Application.streamingAssetsPath);
         Debug.Log("Path of _path variable: " + path);
         if(File.Exists(path) == false){
             Debug.Log("File not found");
         }else{
             Debug.Log("File found");
         }
     }

But everytime it only returns me "File not found". The full output is:

 Path of streamingAssets: C:/Users/user/TouchFollower/Assets/StreamingAssets
 
 Path of _path variable: C:/Users/user/TouchFollower/Assets/StreamingAssets\file.json
 
 File not found

I noticed, that when Unity shows me FileNotFoundException, the path uses "\" sign, but when displaying Debug.Log, the path is shown with "/" sign. Could that be a problem?

Comment
Add comment · Show 8
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 andrew-lukasik · Jun 06, 2021 at 01:06 PM 0
Share

C:/Users/user/TouchFollower/ is a very unusual place to hold your project files. Unity might not have the necessary permissions to always write/read files there. Try moving your project somewhere less ambivalent like D:/Projects/TouchFollower/

avatar image goodgamershow andrew-lukasik · Jun 06, 2021 at 01:49 PM 0
Share

Thanks for the reply! Sadly, I don't have any other disks to put my project to. I tried to move my TouchFollower projects in any other folders, but it didn't work

avatar image andrew-lukasik · Jun 06, 2021 at 01:57 PM 0
Share

Add these two lines:

 if( !File.Exists(path) ) File.WriteAllText(path,"file contents");
 Debug.Log($"File exists: {(File.Exists(path)?"yes":"no")} (path:{path})");
avatar image andrew-lukasik andrew-lukasik · Jun 06, 2021 at 01:59 PM 0
Share

And compare location of this newly created file with location where you expected it to be.

avatar image goodgamershow andrew-lukasik · Jun 06, 2021 at 02:52 PM 0
Share

The code returned: File exists: yes (path:C:/Users/user/TouchFollower/Assets/Strea$$anonymous$$gAssets\file.json). I went to the path and a new file appeared. I noticed, that Unity now sees the file that your code created. But my question is: why doesn't Unity still see my file.json? Maybe the problem is that I created my json file as a simple .txt file and replaced its name with "file.json"?

Show more comments

1 Reply

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

Answer by goodgamershow · Jun 06, 2021 at 03:15 PM

Solution was quite simple: My OS sets any created .txt file back to .txt extension, even if I override the extension. After changing this setting everything started to work properly. Big thanks to @andrew-lukasik

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

127 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

Related Questions

Streaming Assets android 0 Answers

Converting from SQLite Database to JSON 2 Answers

Parse JSON Data with JSON Utility to Dictionary object 1 Answer

can't find json file on android ? 1 Answer

Modifying Json file values 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