Search Unity

Application.dataPath not working in build?

Discussion in 'Scripting' started by T-A-M, Feb 8, 2018.

  1. T-A-M

    T-A-M

    Joined:
    Nov 3, 2017
    Posts:
    4
    So I have a much more complicated script that's unimportant to this question, and I've been simplifying and simplifying trying to figure out the problem, and I've now boiled it down to this:
    Code (csharp):
    1. tempp.text = (Application.dataPath);
    .

    Now, when I run it in the unity editor it works as it should, showing "C://Users/Public/Documents/Unity Projects/Game/Assets" in the text canvas. But after I build the program it shows NOTHING. Not even a little bit of text where the text usually is when I run it in the unity editor.

    Can anyone tell me what could be going on here?
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,446
    Works for me..

    Are you sure the text is visible in build (because of the different resolution, and different path string length)

    Try Debug.Log() the datapath to see if its visible in log file
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Application.dataPath is the path to your assets folder. That's not available in builds, since the Asset folder doesn't exist in builds.

    If you need a folder that exists both in Editor and in builds, that's inside your application, use StreamingAssets, which you get with Application.streamingAssetsPath.
     
  4. T-A-M

    T-A-M

    Joined:
    Nov 3, 2017
    Posts:
    4
    I fixed it. Instead of using Application.dataPath I used
    Code (csharp):
    1. (System.IO.Directory.GetCurrentDirectory()
     
  5. mmmare

    mmmare

    Joined:
    Oct 26, 2020
    Posts:
    1
    Exatly what I needed, thank you!
     
    bravophantom and billionlioe like this.