Game works for only 1 time when doing "Build and Run" and then I get a DirectoryNotFoundException

So in my game it requires you to write an input file name that is stored in the resources folder of my assets.
It works perfectly fine if I ONLY build this game via “build and run”.


I’m so lost, I don’t know where this error can come from. Mainly because it worked the 1st time and the directory does exist. So how come it won’t work after the 1st time?5186069--515267--upload_2019-11-18_4-22-51.png

you could try using StreamingAssets/ folder. (then its available for File.IO operations)

or how are you reading and writing to it? (can you show part of the script)

5186093--515273--upload_2019-11-18_4-34-37.png

what do you use for path? (since resources folder is not really available in build for direct access)

@mgear I use Assets/Resources/CSV/

You should not do like this

path + inputLine.text

there’s a crossplatform function for that

Path.Combine(path, inputLine.text)

@palex-nx Thanks for the advice but that didn’t solve my problem. What did solve my problem though wasNope, that didn’t work. But changing the path to
path = Application.dataPath + "/StreamingAssets/CSV/";
worked so …? What would the reason for that be.:eyes:

Assets/Resources/CSV/ is not available in build, resources are packed.

StreamingAssets/ folder is included as is.

Ohhh I see. Strange that it worked for the 1st time though. Thank you!

Of course, but this will solve another problem you’ll have when (and if) you try to run your game on another platforms. Also path.combine ensure correct path. Also probably you shoul make sure players can’t enter paths starting from … like …/…/…/Desktop/MyHackedDataFile.txt because File.ReadAllText will actually load any file from user’s filesystem into your game.