Saving to Application.dataPath not working on my mac?

Howdy guys,

I’m trying to save a text doc when I close my application so I can get some analytical data from my testers. I save to the file path given by Application.dataPath which works in the editor, however it doesn’t seem to work for the build. In fact, I’m not sure if this is correct, but Unity doesn’t even seem to build a data folder for my mac application, it just builds the application and it seems to work on its own (unlike windows executables).

I’ve searched my whole macbook for this txt document but I can’t find it, so I assume it hasn’t been generated.

Does anyone know what I could be doing wrong? I just want to save the players data locally so I can get them to send it to me with ease…

Any tips are greatly appreciated!

    public void SavePlayerData(PlayerData data)
    {  
        string[] lines = new string[3] {
            "Player name: " + data.playerName,
            "Total play time: " + data.totalTimePlayed,
            "Objective Time: #1 - " + data.objectiveTimes [0] + "\n" +
            "Objective Time: #2 - " + data.objectiveTimes [1] + "\n" +
            "Objective Time: #3 - " + data.objectiveTimes [2] + "\n" +
            "Objective Time: #4 - " + data.objectiveTimes [3] + "\n" +
            "Objective Time: #5 - " + data.objectiveTimes [4] + "\n" +
            "Objective Time: #6 - " + data.objectiveTimes [5] + "\n" +
            "Objective Time: #7 - " + data.objectiveTimes [6] + "\n" +
            "Objective Time: #8 - " + data.objectiveTimes [7]
        };

        using (StreamWriter streamWriter = new StreamWriter (Application.dataPath + "/PlayerData.txt",true)) {
            streamWriter.Write ("\n");
            streamWriter.WriteLine (lines [0]);
            streamWriter.WriteLine (lines [1]);
            streamWriter.WriteLine (lines [2]);
        }

        Debug.Log (Application.dataPath);

    }

As shown in here Unity - Scripting API: Application.dataPath, the datapath points inside the app-file. You can right-click the app-file and click “show package contents”. All the files are in there.

Anyway, did you mean to use Unity - Scripting API: Application.persistentDataPath instead?

1 Like

Oh boy, yep I just discovered this >.> thanks anyway.

I think I should be okay using the ordinary data path for now…