Search Unity

Question Android .txt file resource not imported in APK

Discussion in 'Editor & General Support' started by phandrana_unity, Apr 18, 2021.

  1. phandrana_unity

    phandrana_unity

    Joined:
    Apr 24, 2019
    Posts:
    8
    Hi,
    I'm trying to load a txt file during runtime:
    upload_2021-4-18_9-36-54.png

    I did put my "w1.txt" file in the "Resources" folder but it only works in the editor,
    when I make an Android build it doesn't load my text, it's like my .txt file is not imported in the APK.

    Does anyone have any idea ?
     

    Attached Files:

    Last edited: Apr 20, 2021
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    "Resource" folder or "Resources" folder?
     
  3. phandrana_unity

    phandrana_unity

    Joined:
    Apr 24, 2019
    Posts:
    8
    Resources* I edited it
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Have you tried referencing that asset in one of your scripts? Have public variable on a script and drag&drop you resource on it in inspector.
     
  5. phandrana_unity

    phandrana_unity

    Joined:
    Apr 24, 2019
    Posts:
    8
    No, I'm gonna try. But even if it works I would like to understand why a txt file is not considered as an asset, and automatically packed in the APK.
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    The normal assets are only packed into APK if they are used. I'm not sure about resources. StreamingAssets are always put to apk.
     
  7. phandrana_unity

    phandrana_unity

    Joined:
    Apr 24, 2019
    Posts:
    8
    I also tried putting the .txt file in the StreamingAssets, it doesn't work either with Android build (I used the System.IO.File with the Application.streamingAssetsPath).
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    That won't work, System.IO can't read files from streaming assets. Use UnityWebRequest for that.
     
    phandrana_unity likes this.