Z
Z
Zefirot2021-12-06 22:33:25
Unity
Zefirot, 2021-12-06 22:33:25

How to read a previously saved file on build?

The "prefabricated" prefabs weighed a little too much for me and therefore I went for this option - I make this prefab from several prefabs, then I create a file in the editor and save it in a certain folder, this is a text file and it indicates where which prefabs should be located (coordinates , sizes, etc.), prefab 0.5mb-2mb, but txt with info 3kb, so there is a difference.
What is the problem - during the test everything works and reads, but after compiling and installing on the phone, as I understand it, the file does not read ...
It is stored in my editor

\Assets\Resources\Levels\1\Level-1.txt
\Assets\Resources\Levels\1\Level-2.txt

.... and so on
I read like this
string LevelDataPath = "Assets/Resources/Levels/1/Level-1.txt";
if(File.Exists(LevelDataPath)){
  levelData = File.ReadAllText(LevelDataPath);
  }

Tell me what's wrong, how to correctly fulfill my idea?
That is, in order to read prepared txt files in the game, not saved outside the game, they are still read-only...

Ps - everything works fine in unity at startup...

Pss - do such files need to be encoded? Or when assembling and so you can’t read them anywhere?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-12-06
@Zefirot

Ohh. This is not the first time you have been suffering from this garbage, but you still can’t suffer in any way ... Is the savings really worth these efforts? Is the rest of the game 100% ready?
Answering your question. You have two mistakes. First. For text "configs" you need to use either StreamingAssets (a special folder that is assembled a little differently), or load it as a text resource (I'm not sure about the second one - I haven't used it for a very long time).
The second - I suspect that you are testing on android ... So, reading from StreamingAssets (or from another point in the compiled application) is done not through File, but through UnityWebRequest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question