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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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,724
    "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,642
    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,642
    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,642
    That won't work, System.IO can't read files from streaming assets. Use UnityWebRequest for that.
     
    phandrana_unity likes this.