Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

AssetBundle - cancelling a AssetBundleCreateRequest

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

  1. Valorware

    Valorware

    Joined:
    Aug 25, 2016
    Posts:
    79
    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:
    24,787
    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:
    334
    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
     
unityunity