Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to load textasset from mobile persistentdatapath?

Discussion in 'Scripting' started by kimmo1, Oct 5, 2020.

  1. kimmo1

    kimmo1

    Joined:
    Feb 7, 2014
    Posts:
    49
    on editor it works like:
    data2 = Resources.Load<TextAsset>("rank2");



    but on mobile i cant read it. i have tried like
    data2 =Application.persistentDataPath + "/rank2.csv" ;
    data2 =Application.persistentDataPath + "/rank2" ;
    i have also tried
    string path = Application.persistentDataPath + "/rank2.csv";
    if (File.Exists(path))
    {
    Debug.Log("finds file");
    }
    and checked the file exists...
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    You cannot read Unity's TextAsset files that way. Unity mungles them into something that is universally efficient for the engine.

    Instead do this:

    Code (csharp):
    1. public TextAsset RankFile;
    and drag the rank2.csv file in there.

    Then to get at it, just use:

    Code (csharp):
    1. string data = RankFile.text;
     
  3. kimmo1

    kimmo1

    Joined:
    Feb 7, 2014
    Posts:
    49
    i just cant drag it, i need to download it on my mobile first. it goes to persistentdatapath
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,640
    Can't you save the text to text file and read it using File class?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    If the above is true, then you are NOT doing this:

    Those two things are completely and totally unrelated and absolutely NOTHING to do with each other.

    Download, write and read files using System.IO.File commands and this:

    https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

    OR...

    Use Resources.Load() only as indicated below:

    https://docs.unity3d.com/ScriptReference/Resources.Load.html

    You absolutely MAY NOT mix and match those in any meaningful way.
     
  6. MackKaa

    MackKaa

    Joined:
    Oct 6, 2016
    Posts:
    1
    anybody got an actual update to this like I'm trying to load a csv as a text asset from persistentDataPath not from the resources folder as I need it read and writeable but still be used as a text asset
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Please don't hijack other threads with vague incomplete questions.

    Start your own post, it's FREE.

    If you have an actual problem it will be necessary for you to communicate FAR more effectively.

    Here is how to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Just go run the sample code in the documentation. It works.