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?


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")

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.