getting the path of a file in resources folder

Hello,

I need to pass the path of an image(123.png) that is stored on Resources folder to System.IO.File.ReadAllBytes(). How can I do this? Any suggestions?

Use Resources.Load instead of System.IO.File.ReadAllBytes() to read file from Resources folder as described here Unity - Scripting API: Resources.Load
If you need only path, I think you can try to use Application.dataPath variables concatinated with “/Resources/” string (but I’m not sure, how it will work on differen platforms)

There are no separate files or paths or anything like that when you use Resources. Or rather, they only exist like that in the editor. Once you make a build everything is smushed together into a datafile and you can’t effectively use things like ReadAllBytes.

–Eroc

2 Likes

As Eric5h5 said, everything in Resources folders gets packed together into one asset file. Using Resources.Load() is best, there is also the StreamingAssets folder, but there are some gotchas. (No access on web players, must access with WWW instead of System.IO on Android)
Unity - Manual: Streaming Assets

EDIT: I’m not sure about this, but the actual .png might not even be in the Resources asset after the game is built. Unity may convert the .png to a texture and store the texture instead. StreamingAssets will leave the file untouched.