- Home /
How do I get into my StreamingAssets folder from the various platforms?
I made a 'StreamingAssets' folder inside of my 'Assets' folder and put some things in it which I need at runtime. But I can't quite figure out how to get to it. Whats the proper path and code to use for each platform. Namely, iOS, OSX, Windows and web builds.
i want to make a android game which use $$anonymous$$SAccess Database then i copy my database in Assets/Strea$$anonymous$$Asessts folder (C# language ):i write a function name Read$$anonymous$$B which try to connect to database in windows platform that work well then i understood that i should use www class to access my streams assets folder in android:
IEnumerator LinkStrea$$anonymous$$gFolder()
{
string FinalPath = "jar:file://" + Application.dataPath + "!/assets/" +databasename;
WWW linkstream = new WWW(FinalPath);
yield return linkstream;
read$$anonymous$$DB(linkstream.text);
}
which part of my accessing code is wrong? likewise in start function i add this code:
StartCoroutine(LinkStrea$$anonymous$$gFolder());
You should ask your question using a new question, not ask a question as an "Answer" to an existing, and old question that may or may not be the same question. I've converted your answer to a comment and will be deleting it shortly.
Answer by maxwelldoggums · Sep 27, 2013 at 06:03 PM
While this is an old question, I feel the need to add this for posterity... Newer versions of Unity have a built in reference to the streaming asset path...
"Application.streamingAssetsPath"
will return the full path to the streaming assets folder regardless of platform.
This worked for me on PC builds when Application.dataPath + "/Strea$$anonymous$$gAssets" didn't work!
Answer by kdubb · Jun 06, 2011 at 05:00 AM
Most everything is the same, except on the mobile platforms...
Default = Application.dataPath + "/StreamingAssets"
iOS = Application.dataPath + "/Raw"
Android* = "jar:file://" + Application.dataPath + "!/assets/"
*Android packages are delivered as jar (aka zip) files and are never unzipped (as per the Android platform). This means that on Android the Application.dataPath just points to the jar file itself. This also means you must use something that can access zip files to get at your assets. Unity's WWW class will do this and the base path specified above will work properly with it; just append your file path/name to it.
Application.dataPath + "Strea$$anonymous$$gAssets" is not giving me access to my assets. However something new has come to my $$anonymous$$d as to what might be the issue. If a class extends nothing and is not Static, will it be included into a build of the game?
I am trying to stream an xml file from my strea$$anonymous$$gAssets folder into a class that is neither $$anonymous$$onobehavior, ScriptableObject nor static. Is that perhaps the reason why? This class isn't being included in a build?
I updated my answer... in my first attempt I had forgotten the path separators (I copied my code which uses the Path.Combine method to join the path components), Does that fix your problem?
To answer the question you asked in the comment... no that shouldn't be a problem. I have text (JSON not X$$anonymous$$L) files in my Strea$$anonymous$$gAssets folder and can load them just fine.
Alright I did a test and confirmed the issue is not my class. But it still doesn't work and I'm really at a loss here...
the exact path I am using is this
Application.dataPath + "/Strea$$anonymous$$gAssets/Data/Global.xml"
the file is clearly in my Strea$$anonymous$$gAssets folder, it loads just fine inside the editor, but won't load from a windows build or a web build
Oh no no. 'Data' is a folder I have inside my Strea$$anonymous$$gAssets folder. In the literal folder hiearchy the file is at /Strea$$anonymous$$gAssets/Data/Global.xml
Could that be the issue? Can you not make folders inside strea$$anonymous$$gAssets?
Windows uses "\\" not "/" as a folder separator. $$anonymous$$aybe that's your problem.
For cross platform compatibility use the Path.Combine method to create file paths rather than hard coding the separator into a string.
Answer by aeldron · Apr 03, 2014 at 03:34 PM
string GetStreamingAssetsPath()
{
string path;
#if UNITY_EDITOR
path = "file:" + Application.dataPath + "/StreamingAssets";
#elif UNITY_ANDROID
path = "jar:file://"+ Application.dataPath + "!/assets/";
#elif UNITY_IOS
path = "file:" + Application.dataPath + "/Raw";
#else
//Desktop (Mac OS or Windows)
path = "file:"+ Application.dataPath + "/StreamingAssets";
#endif
return path;
}
I wonder why Unity didn't make the Application.dataPath return the correct prefix in the first place.
Comment note: Did you mean Application.strea$$anonymous$$gAssetsPath ins$$anonymous$$d of Application.dataPath?
This is a very old thread (2014). At the time they didn't have an Application.strea$$anonymous$$gAssetsPath
Answer by DiebeImDunkeln · Feb 23, 2015 at 03:56 PM
is it possible to download files to the StreamingAssetsPath?
$$anonymous$$ight be a bit late for you, but I would recommend creating a folder within Application.persistentDataPath. This will (at least on mobile devices, not sure about PC/$$anonymous$$ac) allow you to download files and then save them using System.IO.
For example:
public IEnumerator $$anonymous$$yDownloadCoroutine()
{
// Specify the download URL.
string myDownloadURL = "http://www.downloadlocation.com";
// Create and start a webcall to the download location.
WWW downloadWebCall = new WWW(myDownloadURL);
// Wait for the download to be done. You can check progress via
//the WWW.progress variable which is a float between 0 and 1.
while (!downloadWebCall.isDone)
{
yield return null;
}
// Define a directory path, on Android this will end up being something
// like "Device/Android/data/com.mycompany.appname/Files/UserDownloads/"
string directoryPath = Path.Combine(Application.persistentDataPath, "UserDownloads");
// Define a file path, must include the correct file suffix (.png, .zip, etc.)
string filePath = Path.Combine(directoryPath, "myDownloadedFile.zip");
// Check if the directory exists. If not, then create it.
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
// If you want to force the file to always be the new downloaded version.
// This finds if the file already exists, and if it does, deletes it.
if (File.Exists(filePath))
{
File.Delete(filePath);
}
// Write the downloaded file bytes to the specified file path.
File.WriteAllBytes(filePath, downloadWebCall.bytes);
}
Answer by shayan_315 · Sep 29, 2013 at 12:03 PM
but you can not retrieve your data directly from your asset folder !! i read in many post but iam surprised why nobody make simple example with www class to load data from apk? most of respondents do not have any experience about making simple example and only like us read unity Streamingassets part then please please make a simple app which only read hello world from streaming assets folder in android (apk) we do not need hint like this at least not any more ,just example please
now, how's that an answer? you are not reading anything right, sir, and there's not much anyone here can do to help you with that. maybe you could start again with the manual.
Your answer
Follow this Question
Related Questions
Best way to Port Unity Windows project to iOS 0 Answers
Windows Editor Extension error with iOS Player 0 Answers
Accesing StreamingsAssets in android (LitJson) 1 Answer
working with mp4 files when supporting both Standalone and iOS builds 1 Answer
What is best way of Creating an iOS app build in Windows and Then on the Mac 1 Answer