Search Unity

AssetBundle - cancelling a AssetBundleCreateRequest

Discussion in 'Scripting' started by Valorware, Jul 26, 2020.

  1. Valorware

    Valorware

    Joined:
    Aug 25, 2016
    Posts:
    91
    Hi,

    I'm creating a AssetBundleCreateRequest using AssetBundle.LoadFromMemoryAsync(path);

    This is to load the music for the current part of the map. However, there is a chance that the user may go to another part of the map, or die, before the assetbundle is fully loaded. In which case, is there a way to cancel the load request? Or somehow just tell it to destroy itself when it's ready?

    Or should I be keeping hold of the AssetBundleCreateRequest and then destroying it if it's no longer needed?

    Thank you!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    It does not seem to have anything to do that:

    https://docs.unity3d.com/ScriptReference/AssetBundleCreateRequest.html

    The parent object doesn't either:

    https://docs.unity3d.com/ScriptReference/AsyncOperation.html

    That said, I think if you just forget about it nothing bad will happen, and I imagine as soon as it is eligible for garbage collection, it's all gone. I seem to recall it only uses a little bit of actual RAM to load an AssetBundle. It is only once you start pulling things out of the AssetBundle that real memory starts being used.
     
    Valorware likes this.
  3. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Im trying to cancel the AssetBundle.LoadFileAsync request and thats working fine, but if i then try to load the same bundle it says its already loaded, but if I try to unload the bundle that loaded before cancelling the request it freezes unity