Search Unity

Editor lag, huge memory usage

Discussion in 'Editor & General Support' started by matiasges, Jan 24, 2022.

  1. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    So when I'm navigating through the scene it gets stuck a lot of times making it annoying to develop a level. I also can't really bake lights because I get an error about running out of memory.
    With the profiler it shows that it is using a lot of memory:

    With the memory profiler this is the memory usage just being idle and with some objects disabled:



    What can I do without lowering the quality of the textures?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    You generally have two options:
    • Reduce their size, by changing import settings or quality
    • Reduce the amount by requiring fewer of these to be in memory simultaneously
      • Check if they are really all needed in memory at this point. That's a whole lot of textures
      • Check what they are Referenced By, should they be referenced? If not, remove the references to them
      • Consider using Addressables to manage their loading as required, instead of always loaded
     
  3. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    How do I check that?

    Yes I tried using it, but it's quite complicated. I really don't get it, the documentation is poorly written.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Right now, by clicking on the blue number in the Referenced By column of the table underneath the Tree Map. And then in that new table, possibly repeating that to follow the chain of references...

    We hope to ship an update pretty soon (ideally by the end of this week, at the latest end of February) that will make this way easier though. Just FYI before you sink too much time into following the references of these thousands of textures, depending on how pressing this is for you.

    Have you read this blog post about Addressables? Maybe that helps clarify some things?
     
  5. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    So here is an example of the biggest texture:

    It's referenced by one. But as I checked all the rest of the references in the other textures they are alright. I mean, why should I delete the reference? If there is something I don't need I just delete it from the scene.


    So according to this guide: Upgrading to the Addressables system | Addressables | 1.18.19 (unity3d.com)

    As I'm already on an existing project I should follow these steps, but they don't explain the reasons behind. Why should I create another empty scene to make the Addressable system work? If my current scene is going to be Addressable why it can't be in the build settings and if is not going to be in the build setting, how am I going to create my built without my scene? Also, what scenes should be Addressable and what shouldn't? In the guide it says that all of my scenes but in the Addressable example project in Github some of the scenes are not Addressable and some are.
    Then in the last step it says to update the code I use to load my scene, however it skips the part when it explains how to do that.

    It's like the first time I heard about the Addressable system, seems to be very important so I don't know why it's so hidden in Unity.
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Did you click on the blue 1? That would tell you what exactly that one thing is that is referencing it and maybe you'd then know if it even should be referenced or if e.g. you just have a reference to a ScriptableObject/Prefab in your Project folder that holds all textures you'll ever need and because it is referenced this way, they are all loaded into memory, even if they aren't used to display anything to the user?

    By the way, by "delete the reference", in that example case of the ScriptableObject above, I mean to not reference the Scriptable Object, or remove the ScriptableObject's reference to the Textures, or turn any of those references into an Addressable AssetReference.

    yeah, if you need all of them in your scene, you'll need a different approach to managing your memory. Some kind of streaming solution, e.g. loading in the textures based on in which area of the scene your player is, loading out those that you don't need. Possibly by splitting the scene up into areas and loading these scenes in and out additive and Async... I can't tell you what the best soultion is, that depends on your project, but you'll be needing something if you need all of these, because, I don't know what platform you are targeting but 23 GB of texture memory will probably not fly on most of them.


    For your questions around Addressables, the addressables subforum is probably the better place to ask these as my own experience with them is limited to having converted the 3D Adventure game pretty rudimentary to addressables. I'll try to answer some of the questions you already raised here though, as best I can:


    If the Scene isn't addressable, it is not loaded in via the Addressables system, so all the assets in it that it references too won't be loaded in using the addressables system either.

    With the exception of those only referenced to via an AssetReference.

    So if you have a cube that uses a material that uses the Texture2D "CubeTex", and that material and texture are marked as addressable, then having a scene with that cube in it in your build settings will mean that the material and texture will end up in your Scene Data blob AND the Assetbundle build by the Addressables system. This will bloat your build size and could even cause the Material and Texture to be in memory twice if also used in an addressables-way. E.g. if you have a component in your scene, that has an AssetReference field to the material. If you then load that AssetReference, you have duplicated your memory use for these.

    In this example, if the scene was not in the build settings but only referenced via the Addressables system and loaded in via the systems APIs, then both the cube, and your component would load the same material and texture from an asset bundle.



    If you have a situation like in my first example where you just hold a bunch of references to assets that are otherwise not used in your scene, say for example, the card face images used in a memory game are arranged in 3 decks and you only ever need one deck at a time, but hold a reference to all 3 decks to swap out the textures used on the cards between rounds, then you could easily just transform the references to the decks to AssetReferences and load or unload them as needed that way. (in this example the scene may have your full grid of memory cards already in it but with blank faces, so no direct references to the textures in the decks that should be loaded using addressables)


    I hope the above example clarified this somewhat already but basically, if you plan to use Addressables to bring your memory usage down and only use if on specific assets, like the memory card faces, and if these specific assets are otherwise not directly placed or referenced in the scene (unless that's through and AssetReference) then your scene doesn't have to be addressable.

    yeah, i guess it's missing a link to this page.
     
    matiasges likes this.
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    by having a scene that is in the settings and that contains an object with a component that will load the scenes you need via an AssetReference. Then you just need to build your Addressables content before making a build (in the editor, everything should by default still just work) and all the information should be available to the build via Asset Bundles. You can still start the game from your scene that is now no longer in the build settings, but you can't use SceneManager APIs to load other addressable scenes. You'll then have to use the Addressables APIs for scene loading, as I linked you to above.
     
    matiasges likes this.
  8. matiasges

    matiasges

    Joined:
    Jan 24, 2021
    Posts:
    142
    Alright, I'll take a look into all you said. I thought with LOD and camera distance was enough. I get over 100FPS right now and the lights are not baked, so I'd probably get more.
     
  9. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    Took a little longer than we hoped but we've released that 0.5 Update now.
     
    matiasges likes this.