Search Unity

Optimizing my game. Memory Profiler showing assets that aren't loaded

Discussion in 'Editor & General Support' started by whidzee, May 11, 2020.

  1. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    I am at the optimizing stage of my game. I am digging through the memory profiller and I found that some assets which are in memory shouldn't be there. They are either in a different scene completely or they are unused assets in my production. There are some models and textures that I have made early on but stopped using. they are not used anywhere in any of my scenes yet they are still loaded.

    Why would unity be loading into memory all assets from my game instead of just the ones needed in the current scene?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,451
    Hi,
    Are you profiling the editor (capturing memory snapshots while in Playmode)?
    There's all sorts of reasons why the Editor could have loaded some asset into memory that shouldn't be needed for the current state of the Playmode (only one obvious example being that you have an inspector open on it but there's way more) so you'll need to profile a build to see a clear picture of what is actually loaded in memory.

    Also, are you using the Memory Profiler package? That should help in tracking down why the asset is in memory.
     
  3. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    I was actually using the memory profiler package and I was checking it in a build, not the editor. This is why I am so confused.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,451
    Have you gone through the references to these assets? I.e. clicked the RefCount number in the table view? (I know this is sub-optimal, a better way to inspect references is in the works)
     
  5. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    yeah I've dug down deep and found the texture is referenced by a material, and the material is not assigned to anything.
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,451
    Also, are you using AssetBundles?

    Also, assets aren't unloaded as their scene is unloaded, but only until after the next destructive scene load or once you call Resources.UnloadUnusedAssets. This is a loading time optimization in case the next scene still uses some of the same assets.