I'm trying to get all the json files from the StreamAssets folder on Android using this code

string filePath = Application.streamingAssetsPath; DirectoryInfo dir = new DirectoryInfo(filepath); FileInfo[] files = dir.GetFiles("*.json"); foreach (FileInfo file in files) { GameObject catalog = Instantiate(catPrefab) as GameObject; catalog.name=Path.GetFileNameWithoutExtension(file.Name).ToString(); Debug.Log(catalog.name); } 

On the Unity emulator, all files are loaded, everything works fine, but when I download the APK on Android, no file is found.

put a check on the existence of the file

 DirectoryInfo dir = new DirectoryInfo(filepath); if (!dir.Exists) { Debug.Log("Нет такого каталога"); } 

How to make everything work on Android? thanks in advance

  • maybe there are not enough rights ...... in general, as a pribluda, why not write logging logic? and in the case of warnings or errors, write to the log and display it on the screen, and not in Debug.Log , so that you can visually analyze the cause yourself? put a try catch, too, as it should be, and pledge a problematic place - Alexey Shimansky
  • Unfortunately, I'm new to this business. I moved from web programming here and much is not clear. Can you write more in detail with the code? - bellator001
  • @ bellator001 Tell me, please, what do you mean when you write "no file finds"? From your code, I see that you are outputting file names to a debug log, but it’s debag log is a unit editor interface element. Try outputting file names to a UI element, for example. - eastwing

0