Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to prevent our localized assets to take up memory ?

Discussion in 'Localization Tools' started by jeango, Mar 22, 2023.

  1. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    After profiling our game we noticed it was taking up uncanny amounts of memory because our localized audio assets are not being unloaded.

    So as the player plays our game and progresses, more and more audio assets are loaded into memory and never released afterwards, eventually causing the game to crash on mobile.

    Since the loading is happening inside of the localization system, we don't have access to the AsyncOperationHandle required to release the addressable. So far the only solution we have found is to quickly switch the locales as the scene loads, but surely there must be a better way. What's the proper way to manage this?

    hoping @karl_jones could chime in on this
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,468
  3. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    Thanks, but what if we're loading the assets in a different scope?

    To give some context, we've created a LocalizedAudioPlayableAsset (using Unity Timeline). It extends the AudioPlayableAsset class, with an added Localization layer. We set the "clip" whenever CreatePlayable is called to the current locale, this is to allow us to visualise the waveform in the editor outside of runtime. It also rebuilds the entire Playable Graph whenever the locale is changed, should the player change the locale while a timeline is running.

    However, this is far more complex than just playing a clip, and we don't know exactly how to keep track of all the handles. However in the link you gave I see that there is a ReleaseAssets() method, which is apparently what is being called when we do our locale change switcheroo. Since there's not really any point in releasing assets independently (the reference counter is decreased, but memory is not freed until all adressables in the bundle are released) it would make sense for us to just do a ReleaseAssets() on all the relevant tables when we unload the scene.

    Does that sound like a proper way to do it?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,468
    Releasing all assets should work, it may mean that an asset gets reloaded if it's used again but that should be fine.
     
  5. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    So... we noticed another thing, aparently Localization forces us to have one single bundle (Localization-Assets-English_Assets_All.bundle) with all of our games' audio assets. We would like to be able to create one addressable bundle per scene. We have one assetTable per scene but they all wind up in one greyed out group (localization-assets-english).



    When looking at the Adressables Event Viewer, when we do a ReleaseAssets() the adressables are correctly released, but when we look at a snapshot of memory usage in the profiler (from a development build, not from the editor), we still see the assets in memory.

     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,468
  7. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    Thanks, we're slowly starting to figure out what our problem is:

    We're using Easy Save Manager to save some state
    Each state is a scriptable object that determines which timeline should be played on the playable director (so it references a timeline asset)
    That timeline asset itselfs references audio clips and spine assets
    Since easy save keeps all those references live, as we go through the different scenes of the game, more and more references to various states are kept on the persistence save manager, and via all those chain references, nothing ever gets unloaded.
     
    karl_jones likes this.