22
2017
Load AssetBundles with Caching
Small sample script to load assetbundles.
Features:
– It first loads bundle hash from the manifest file on server
– Then uses that hash string as asset bundle loader parameter (to use cached version if available, see docs)
– Instantiate gameobject after loading
*Note: there is some memory leak happening with this script (unity 5.5.3)
Related Posts
8 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
How to use AssetBundles
https://unity3d.college/2017/06/04/use-assetbundles-assetbundlemanager-update-unity3d-games/
Great post, great script, thanks!
I have a question.
Why do you use random url parameter in line 84?
www = UnityWebRequest.GetAssetBundle(bundleURL + “?r=” + (Random.value * 9999999), hashString, 0);
I would expect it would cause redownloading of the asset no matter if it is cached or not, maybe I am wrong.
Tomasz
yeah, it was added to avoid getting cached bundle information from server, but my understanding was that if the hashString is supplied, it wouldn’t load the whole bundle again (if its locally cached already).
Never actually measured or checked if that’s true.. : D
I wrote a different approach, instead of using UnityWebRequest, I use WebClient to download
encrypted assetbundles as in byte[], and decrypt them, all happens in a seperate thread. And built in caching system won’t work with this approach, so I wrote my own caching system, works just fine so far.
nice! if you want to share, can post to https://github.com/UnityCommunity/UnityLibrary/
Hey mgear,
Thanks a lot for this script, I’ve been struggling to understand how the caching system is working with asset bundles since a too much time, that helped a lot ! 🙂
thanks a lot mgear. Really saved a lot of time. Code worked for me with couple of changes
nice, feel free to post your code or updated lines (if its related to some newer unity api or such changes/fixes)