Addressable Directory and Addressable Loading Logic - unity3d

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?

Related

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.

Get Assetbundle name before loading

I'm working on a project where the user can load assetbundles during runtime, so we only have limited control over what assetbundles are used. Because of that, we have to be careful when we load multiple assetbundles since AssetBundle.LoadFromFile(bundlePath) returns null if a bundle with the same name is already loaded. It will write this Error to the Log:
The AssetBundle 'testbundle' can't be loaded because another AssetBundle with the same files is already loaded.
The main problem now is that I couldn't find a way to get the name of the assetbundle in the file without loading the assetbundle. Using the filename is a workaround, but won't work if people rename the assetbundle file.
We ended up with a very ugly workaround:
Before we load an assetbundle we have to call UnloadAllAssetBundles. This works because there will never be a name clash. But also makes caching impossible, and we load the same bundle multiple times.

Streaming assets folder VS Resources Folder in Unity?

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.

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()

How can we make a nested directory in resource folder to put the xmls with same name?

How can we make a nested directory in resource folder to put the xmls with same name for different folders.And how we can read it using path in iphone app programatically?
Actually i want to make like resource>a>b>some.xml
again in resource like resource>f>g>some.xml
and so on...how ever both xml is containing different data in it.and also tell me the way how we can read it in iphone application.
You cannot use the same filename, even if they resides in different folders.
Instead, as a workaround, you can name the files like:
a_b_some.xml
f_g_some.xml
you can create a folder structure on your system and then directly add the folder to your XCode Project under resources by drag-drop.
this folder must display in BLUE color (physical grouping in folder on disk) rather than YELLOW (logical grouping in project only) just like native folders on mac. like this you can put same file in different folder hierarchy without any problems.
you need to create a absolute path to your file whenever you want its access your file [NSBundle pathForResource:] will not work in this case as it does not have access to your custom folder hierarchy.
best of luck.