playMaker

Author Topic: Cached Asset Bundle with UnityWebRequestAssetBundle  (Read 151 times)

PleaseHelpMe

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Cached Asset Bundle with UnityWebRequestAssetBundle
« on: May 24, 2020, 11:54:26 AM »
Hi, I'm been trying to experiment with DumbGameDev's "Asset Bundle Unity Web Request" to try to cache the download to disk. Currently it does not cache the AssetBundle to disk because it uses DownloadHandlerAssetBundle which is a "Standard constructor for non-cached asset bundles." Therefore, it needs to be re-downloaded every time and I need it to be cached.

I currently use "WWWAssetBundle" created by the PlayMaker team and "AssetBundle Load From Cache or Download" by DumbGameDev and they both work pretty much the same. However, they both use WWW which is an insecure method and not allowed by iOS. Both actions work the way I need it to, which is that it downloads from the URL. If it is not cached then it will download the AssetBundle into cache and load it into a variable. If it is cached then it will NOT download and will load the AssetBundle cache into a variable.

According to: https://blogs.unity3d.com/2020/04/09/learn-to-save-memory-usage-by-improving-the-way-you-use-assetbundles/, it says that
"If you provide a version or a hash argument to the UnityWebRequestAssetBundle API, Unity stores your AssetBundle data into the disk cache. If you do not provide these arguments, Unity uses the memory cache. Note that Addressables uses the disk cache by default. This behavior can be controlled via the UseAssetBundleCache field."

I have been experimenting and have not really been able to correctly figure this out. Using DumbGameDev's "Asset Bundle Unity Web Request" as a base I have tried to perform
Code: [Select]
UnityWebRequestAssetBundle.GetAssetBundle(uri, version.Value); to add a version to it so it can cache the download. But I am getting cannot convert FsmInt to uint error.

Someone has successfully achieved this here: https://forum.unity.com/threads/asset-bundle-saved-in-cache-but-allways-download-again-on-restart.618169/

However, with my limited coding knowledge, even following it I was unable to achieve what I wanted. I was wondering if someone could get a UnityWebRequestAssetBundle to download and cache the AssetBundle. If the action is run again and it sees that there is a cached AssetBundle from that download link it shouldn't redownload it and simply put the AssetBundle into a variable object just like "WWWAssetBundle".

I have already gotten in contact with DumbGameDev's tcmeric and he stated that it was best I asked here. I ask this because you guys have created another UnityWebReuqest command with "Web Download Request" and I am wondering if you knew how to do UnityWebRequestAssetBundle

Any help is appreciated, thank you.
« Last Edit: May 24, 2020, 12:13:34 PM by PleaseHelpMe »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: Cached Asset Bundle with UnityWebRequestAssetBundle
« Reply #1 on: May 25, 2020, 01:00:33 AM »
Hi,

 I have a project which likely will involve Addressables and I'd like to start providing playmaker support for it, so I'd rather straight away support caching for addressables, what do you think? are you using bundles because addressables don't fit your needs or else?

Bye,

 Jean

PleaseHelpMe

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Re: Cached Asset Bundle with UnityWebRequestAssetBundle
« Reply #2 on: May 25, 2020, 02:47:24 AM »
quote cut

That is awesome, I'm simply using already made playmaker actions. Currently, I am just using AssetBundle for how the actions are written which is to Bundle the whole scene together. I am using AssetBundles because those are the available commands on playmaker and I myself am not a coder.

Addressable would split downloads as well as download size. Allowing for downloads to be made on the fly during gameplay and during the same scene as well.

The problem is that I do need a more immediate solution and I do not know how long Addressable commands for playmaker will take.

However, if you understand the UnityWebRequestAssetBundle enough to append/edit DumbGameDev's "Asset Bundle Unity Web Request" to allow it to cache. Currently, the action will download an AssetBundle using UWR but it just doesn't cache it. So if you don't have to waste too much time on it that would great for me.

But, I would much rather make use of Addressables if that comes out soon.