Search Unity

switching scene while assets are loaded causes the error

Discussion in 'Asset Bundles' started by andrew_pearce_, Mar 24, 2019.

  1. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    169
    Hello,

    Documentations says that all assets bundles should be loaded async, as well as assets themselves. Everything work perfect until today I created scenario when app gets crashed.

    I simply switched the scene, while assets were loading asyn via coroutine. As a result, coroutine never finished to unload bundle and reference to is was lost. Next time I tried to load asset, I got error that it can no longer be loaded as it's already loaded.

    What should I do to avoid such situation?

    Thanks
     
  2. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    169
    Thanks this forum to be my rubber duck debugger =) The solution is simple... the whole asset loading class extends a mono behavior so I simply unload all bundles OnDestroy method.

    Those scripting languages taught me bad, relay on garbage collector and do not clean up memory by manually destroying the objects. This situation is good example how big problem this could cause and how difficult it would be to reproduce error based on user complain =)