I wanna query a certain folder for level files (text) that have been inserted during the course of the game (persistent throughout game starts). There can be an infinite amount of those level files. In my first project it worked like this: Code (CSharp): if(Application.platform == RuntimePlatform.Android){ dataPath = Application.dataPath; } FileInfo loadFile = new FileInfo(dataPath+"/save/"+slot); StreamReader reader = loadFile.OpenText(); Now, querying a folder seems to be a problem somehow. No matter which manifestation of dataPath I use Code (CSharp): dataPath = Application.persistentDataPath; dataPath = "jar:file://" + Application.dataPath + "!/assets/"; dataPath = Application.dataPath; when running the code, the game stop executing the scripts, does NOT throw a UnityException and obviously my game breaks. I found a lot of threads about this topic but nothing I have read behaved how I expect it. So the question is: How do I query a folder on Android for files if the second line breaks the code: Code (CSharp): DirectoryInfo levelsDir = new DirectoryInfo(dataPath+"/levels/"); FileInfo[] levelsDirArray = levelsDir.GetFiles("*.txt"); For over a week I could not find an answer, so thanks for your help
Are these level files shipped with the game? If so, take a look here: http://forum.unity3d.com/threads/file-input-best-practices.336965/ http://forum.unity3d.com/threads/storing-a-my-data-file-into-ios.326974/#post-2120459
Depends on what you mean with "shipped with the game" They are not there when you download the game. But they can be unlocked ingame. They are generated randomly with names like 10000, 10001, .... 20000, 20001, .... 50000, 50001.
By shipped with game I mean are the text files bundled with the build in Unity (ie will be stored as an asset) Sounds like the links above are what you need by your description.
actually I think they provide the solution for when you have built-in files. If I got that wrong, please explain to me once more. They are basically like regular save files, except I don't know their names, so that's why I need to query a whole folder. I don't understand why this is a problem or which function I must use. I can not make any presets of them.
But your description is of built-in-files no? Are you downloading these files? How do these files get in this "whole folder" Mobile and Web platforms often do not have such features available (they are more sandboxed than that) that's why these asset API's exist.
So how do you create a savegame if creating text files isn't possible? They are generated randomly at runtime. They are plain text files and it completely works when using the Editor or with the savegame file (there is only 1).
I'd suggest using PlayerPrefs if that suffices (again, a storage mechanism that works on all platforms). You can save to the filesystem on some platforms (WebGL - no chance) and other have various restrictions etc. Unless PlayerPrefs will not work, I'd use that for game saves. If they are generated randomly at runtime, could you not just keep the 'seed' for the random number generator as a player pref and regenerate from that as needed?
PlayerPrefs seems definately the wrong mechanism for that. It is not a player preference but a file with a lot of information. Even IF PlayerPrefs could store a seed, what would be the key for theoretically 50000 files? I dont really understand why this simple things turns out to be that complex and why nobody has an answer to that
It's not complex at all. How about explain in detail what it is your're doing and we'll let you know what is the right or wrong mechanism. If something is generated at runtime then the seed is a single integer no? (the seed to the random number generator) so any randomly generated level should take at most 1 int to store... no? Where does 50000 files come in to it? You'll need to explain what you're wanting to do - you're initial description made no indication of 50000 files.