- Home /
Script to load csv after build
This code works to load up my csv file to load up the world components, but only in the editor when I hit "play" works fine. What it doesn't do, is if I make a build, it doesn't load from the csv file. I've seen things about Unity's Streaming Asset path yet I'm not sure how to apply that to my script I have here. Is that even what I need? How I make my csv file loadable after a build?
basePath = Application.dataPath;
basePath += "/Scenes/BoardCSV/Board.csv";
width = height = 0;
string[] rows = System.IO.File.ReadAllLines(basePath);
foreach(string row in rows) {
++width;
string[] columns = row.Split(',');
foreach (string column in columns) {
if (width == 1)
++height;
}
}
Answer by Will_at_BridgeWorxGames · Nov 12, 2020 at 12:54 AM
I fixed it. I used this Unity doc as my resource.
1. Created Resource Paths
It states that Mac and Windows builds have different locations for their resource folders. I used the branches mentioned in that doc by creating each folder individually to re-make each path for both Mac and Windows:
2. Updated Code
Then I changed the code a bit to this:
basePath = Path.Combine(Application.streamingAssetsPath, "Board.csv");
width = height = 0;
string[] rows = System.IO.File.ReadAllLines(basePath);
foreach(string row in rows) {
++width;
string[] columns = row.Split(',');
foreach (string column in columns) {
if (width == 1)
++height;
}
}
3. Added IO Header
Lastly, I had to add "using Unity.IO" as a header file.
Answer by unity_bXBCaxYxZaR9Gw · Aug 16, 2021 at 09:02 PM
Hello there! I've got a question.
I've got the next task.
I have text objects in my UI. They recieve text from .csv file.
But I want to change this .csv file after I build my game. To change the text in the text objects by changing the .csv Would this script help me with this task?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Importing Assets after Build 0 Answers
Keep the link to a csv file on build 1 Answer
Command-line build 64-bit 1 Answer
framework not found FBLPromises after build in XCODE...ERROR 1 Answer