1

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?

2 Answers 2

3

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.

16
  • So I assume I need a local file to track my initial item id and version right? And if my item on server has newer version, I delete my old assetBundle and load from web. But how to implement that tracking system? If it is a text file, people will easily modify that and it will be a problem.
    – weijia_yu
    Commented Jul 6, 2017 at 0:49
  • Usually, you include the minimum objects that are required to play to the in the AssetBundles and package it with the game like I described above. It cannot* be deleted. That's why I call it minimum. Now, as for the updates or extension packs that includes new Objects, download this to Application.persistentDataPath/yourfolder/. It will work on any platform. The Asset you downloaded and saved to Application.persistentDataPath/yourfolder/ is the one you can download or update. You can create a simple data structure you can use to keep the version.
    – Programmer
    Commented Jul 6, 2017 at 1:51
  • This post I made has a function to simple save/load/delete that data from Application.persistentDataPath. As for people being able to modify a file, you cant stop that. You really can't if it's running on their device. Just add basic encrypt/decrypt function to save your files but they can still be hacked regardless.
    – Programmer
    Commented Jul 6, 2017 at 1:55
  • 1
    Thanks for the tip!
    – weijia_yu
    Commented Jul 6, 2017 at 3:41
  • 1
    @TomerPeled No. You can have many AssetBundles shipped with your game but cannot update it. Any Unity function that looks like it is updating it is only making a copy or downloading a new one.
    – Programmer
    Commented Oct 5, 2017 at 21:05
0

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

3
  • I thought the version number is not in the local bundle, it is just a random number for UnityWebRequest.GetAssetBundle to grab update for server?
    – weijia_yu
    Commented Jul 6, 2017 at 3:26
  • What i meant by you have the version number inside the local bundle is that you create a TextAsset indicating version and other properties of the assetBundle and package it along with the bundle. @ywj7931
    – Suraj S
    Commented Jul 6, 2017 at 3:32
  • That way, others cant modify it since its not a text file
    – Suraj S
    Commented Jul 6, 2017 at 3:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.