0
\$\begingroup\$

This question is based off of a previous one.

How to read a data from text file in unity

But I cant get the code to work for my purpose. I want to be able to choose which CSV files needs to be edited instead of just assigning one file.

Here is the code

private void readData()

{
    TextAsset csvFile = Resources.Load("Assets/Resources/Test1.csv") as TextAsset;

    string[] records = csvFile.text.Split(lineSeperater);
    foreach (string record in records)
    {
        string[] fields = record.Split(fieldSeperator);
        foreach (string field in fields)
        {
            contentArea.text += field + "\t";
        }
        contentArea.text += '\n';
    }

I want to access the file using a given link and then write to it. but for some reason it keep saying "Object reference not set to an instance of an object" referring to "string[] records = csvFile.text.Split(lineSeperater);"

I'm new to coding so it might be missing something silly. but as far as i know it should make sense? as csvFile is given the usl, but the url is not being found when its searching for csvFile.text, but then again, i might be completely wrong.

Could someone maybe help me and guide me in the right direction?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Don't neglect to check the docs on Resources.Load:

The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

So Resources.Load("Assets/Resources/Text1.csv")

should instead be Resources.Load("Text1")

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .