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

Build export cannot read csv from the resources

Discussion in 'Editor & General Support' started by v_chs, Feb 9, 2021.

  1. v_chs

    v_chs

    Joined:
    Dec 11, 2019
    Posts:
    64
    I build a unity game, that reads data from datasets, located in the Assests/Resources folder and, in development mode, works fine. When I build it, in both platforms (Mac/Windows) it cannot read the datasets. Is there any problem with Unity reading datasets in production mode?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,757
    If you are using System.IO to read files, that will never work for Resources folders. Unity mooshes all the files into its own internal format at build time.

    Instead, use Resources.Load<TextAsset>() to get at TextAsset-ish things like txt, json, csv, etc.

    Remember you do NOT supply "Resources/" as part of the path and you also do not supply the suffix file extension. You only supply the path and asset names:

    Code (csharp):
    1. var myText = Resources.Load<TextAsset>( "Datasets/MyCSVFile");
    ALTERNATIVELY , an entirely different way to get at data is to use the StreamingAssets folder, in which case none of the above applies. Check the docs on StreamingAssets for how to use it.
     
    v_chs likes this.
  3. v_chs

    v_chs

    Joined:
    Dec 11, 2019
    Posts:
    64
    Thanks a lot for the reply. I'll go for the streaming assets, because I use the way you suggest:

    Code (CSharp):
    1. Resources.Load<TextAsset>("mlr/" + gameObject.name);
    Hope it's not complicated :/