Streaming assets folder VS Resources Folder in Unity? - unity3d

I want to Know the difference between Streaming assets folder and resources folder in Unity3d?

Want to extend answer by holo559.
Streaming Assets are just copied as files and can thus be accessed as such. Useful for including files like sqlite databases or other files you want to be able to use StreamReader on. They do not work on some platforms such as WebGL due to the web not having filesystem support. Can also be interchanged during runtime.
Resources are embedded into your program and are therefore platform independent. Useful for having example text files for configurations such as json or yml files.

Streaming Assets :
Any files placed in StreamingAssets are copied as it is to a particular folder on a target machine. Any asset placed inside StreamingAssets can be used while the application is running.
Resources :
Resources class allows you to find and access Objects including assets. You can access assets using "Resources.Load" stored in Resources. All assets in the "Resources" folders will be included in a build. This resources folder comes handy when we have to access multiple assets, instead of using their path names we can use its reference.

There are a few more differences worth mentioning:
1- Unity will include the dependencies of an asset when you put it in a Resources folder, Streaming Assets won't.
2- Using Resource API you can both load an asset and deserialize it. using Streaming Assets you have to do all file operations manually.
3- Resource API allows you to Unload unused assets.
4- Unity will try to create a lookup tree when your game launches, depending on the number of assets, this can take time.

Related

Addressable Directory and Addressable Loading Logic

I have a question about how Addressables deal with Addressable directories I hope you could help me with.
Let's say I have bunch of assets (prefabs or sprites) inside a directory (let's call it "mydirectory") which I want to load dynamically at runtime using Addressables; Instead of marking each of the assets as Addressable, I make the containing directory (i.e. "mydirectory") as addressable. Loading assets using Addressables API works without any problems this way.
The question however is: When I load one specific asset from the assets in "mydirectory" using Addressables.LoadAssetAsync(".../mydirectory/asset1"), will other addressable assets in the directory gets loaded in the memory because they are in the same directory and under the same addressable entry in the addressable group? Or Addressables deal with each asset in that directory as if they are a separate entry in the addressable group?

how to bundle flutter desktop assets into a single file for production build

after building the flutter project for desktop, flutter copies all asset files inside the assets directory into the build/flutter_assets/assets which are easily accessible and modifiable (which is not secure at all!), user can change the whole images easily and do some kind of modding the app with no experience required! or even in the worst situation with modifying the AssetManifest he could change the runtime dynamic libs with the malicious libs and get a hook from the app.
most modern frameworks/languages have the option to embed the resources inside a single file (that makes it harder to modify the files / repack the resource file) for example C#(WPF/Win32) embeds the resources in the resource Resource section or even Electron (Javascript) embed the whole resources into a file (it's easy but better than nothing)
I didn't find any similar behavior in Flutter Desktop (Windows/Mac/Linux) is there any alternative for flutter?
For now [12/12/22] it seems flutter desktop won't use resources to bundle the resources into a single file.
So I've created two separate libraries to achieve this
https://github.com/kooroshh/bundler that compresses the whole given assets into a single file and encrypts it with AES-128
https://github.com/kooroshh/flutter_bundler that reads the bundle file from and decrypts it into the memory that can be used with Image.memory or Direct file access using Virtual Files.
I hope an official solution gets implemented in the flutter framework.

Is there any way to split data files into smaller chunks in Unity WebGL builds?

I am limited to the size of web applications I can build by the "Build\application.data" file.
I.e if its over a certain size I cannot upload it certain hosts, github, etc.
Ideally I would like to split the application into multiple data files under a certain size, while the application is still executable.
How would this be possible? Is this something I can do from Unity build configuration?
Can I do it after the build is done?
Can I split the file into chunks by archiving it with zero compression, and somehow still execute it from the browser? There is a file called Build.Loader.js, is it something that can be edited for this purpose?
This is for the purposes of using the application after it has been uploaded, not sharing it, I do not want to compress it into separate archives, or use gitlfs, I've tested this and the application does not work from the browser with github and gitlfs.
Thanks
Unity has 2 technologies for split data file:
Asset bundle
An AssetBundle is an archive file that contains platform-specific
non-code Assets (such as Models, Textures, Prefabs, Audio clips, and
even entire Scenes) that Unity can load at run time
Addressbles
The Addressable Asset System allows the developer to ask for an asset
via its address. Once an asset (e.g. a prefab) is marked
"addressable", it generates an address which can be called from
anywhere. Wherever the asset resides (local or remote), the system
will locate it and its dependencies, then return it.
Both technologies create separate files that you can host on a server and download as needed. Addressable is a newer technology that Unity team recommends.
Probably the total size of the bundle will grow, but user will be able to download only the necessary assets and the amount of data for the user may decrease
If you do not use Unity solutions, you can divide data file into parts. But on the client side (javascript) you will need to download all the parts, connect them and pass to Unity loader. You probably won't be able to use the browser's built-in gzip or brotli (not sure). It seems to be quite difficult.

When to use assets in Flutter

What is the best way to use assets in Flutter , for example if i have a file for app configuration , should I store the file by getting the app directory using the path_provider plugin -without using assets- and store it ?, or should I add the file to my program folder -add the file to my assets- ?
the same question if I have a small Sqlite database.
and which of these methods is faster , and which is more secure ?
Assets are files that you add to your app during development. You can load them with rootBundle.load() or rootBundle.loadString() but you cannot modify or delete them.
In the app's directory you can store any files that your app downloads or generates from the internet while running. These files can then be opened, deleted, modified, etc. To access your app directory you need the package path_provider, which tells you the path to your app folder.
A sqlite database is normally stored in the app directory. An example package would be here sqflite.
For speed and security I can't make a difference. An app directory is designed so that only the app can access it. Assets are a part of the app, the application file can theoretically be unpacked by anyone. Therefore I would at least not store secret things in the assets.
Well, if by app configuration you mean the user's settings you can use Sqlite, SharedPreferences or Hive (Hive shows a benchmark that says that it is faster than SharedPreferences).
I believe that assets folder is used to store some common files for the app, like images, icons, fonts, etc. And I think that isn't recommended to store files with some kind of config file, mainly with critical info about the app configuration.

Unity3D update local assetBundle

In my project, I have a bunch of items stored as assetBundles. In my server, I stored a list of item including their id and version. So ideally, using UnityWebRequest.GetAssetBundle(uri, versionId)I just get the item lists every time I open the app, if first opened, it will download every item; if secondly open, it will only download the one I have updated the version number on the server. Everything is very easy.
But now, I want to store those assetBundles at local first so that people don't need to download with cellular data.Is there an easy way to manage those assetBundles?
You can place the AssetBundles in the StreamingAssets folder. This is what the folder should look like:
Assets/StreamingAssets/
When you build the project, Unity will include the AssetBundles in the build. Of-course, you can use the Resources API but the StreamingAssets folder seems to be more appropriate here.
Once you place the AssetBundles there, you can use Application.streamingAssetsPath and AssetBundle.LoadFromFile to load the AssetBundle.
You can also use the WWW API with Application.streamingAssetsPath to load the AssetBundle.
You 'dont' keep a local text file. you have the version number inside the local bundle. You have a text file on the server. then get the text file, compare that with the version in the bundle and update if necessary.
In the server, you can have an assetbundle with only a textasset to secure that too.
you can build the asset bundles and have them in the streamingAssets folder or anywhere and use AssetBundle.LoadFromFile()