can't seem to open binary file after game is built (inside asset folder)


My game has a campaign system in which every map is a separate file I made in my custom map editor.
So I save the map (which is a binary custom file) and so everything works great in the editor, I can open the file and load the map, but once I build the game and try the campaign in the built version of the game, it can’t seem to locate the file and thus, open it.
The file is located in the Asset folder of my Unity project. I have tried to move it to the resources folder but same problem.

Is there something I ignore about unity destroying custom files once the game is built ? Then destroying my campaign files ? I don’t really understand the problem as it seems to find everything when I am in the editor. Hope my question is clear enough !

No, Unity does not “destroy” files. It’s actually the other way round. No source files will be included in a build. Your Assets folder is a project staging folder. Unity only includes used / referenced assets in a build. However not in the source format. Assets are packed / converted into Unity’s asset format.

What you probably are looking for is the StreamingAssets folder. Please read the documentation carefully. If you build for Android or WebGL the streaming assets can not be accessed through the normal file system. In this case you have to use a UnityWebRequest or the WWW class.

To whomever who has the same problem as me, here is the solution.
Go to your Asset folder in your unity project, there create a “StreamingAssets” folder, and this folder will be accessible once your game is built.
the code to use is the following :

file = File.Open(Application.streamingAssetsPath + "/Campaign/" + MainMenu.mapName, FileMode.Open);