Application.dataPath not working in build?

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: 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?

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

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.

10 Likes

I fixed it. Instead of using Application.dataPath I used (System.IO.Directory.GetCurrentDirectory()

14 Likes

Exatly what I needed, thank you!

2 Likes