Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Resource Checker (FREE) - List Texture/Material/Mesh Memory use in scene

Discussion in 'Assets and Asset Store' started by SimonOliver, Apr 13, 2012.

  1. sicklepickle

    sicklepickle

    Joined:
    Apr 8, 2012
    Posts:
    44
    Not even sorry about going necro on this thread - this tool's perfect and I hope more people get a chance to use it.
    Thanks for sharing!
     
    JoeStrout and Lars-Steenhoff like this.
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,013
    Absolutely brilliant tool. I was trying to find out where my memory bottleneck was and within 15 minutes I found all the issues and reduced my texture usage by half. So, I went from a game crashing on the Wii U to one that is not only running, but running smoother.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I've just discovered this tool. It looks really handy! But most of the textures are showing up as "0k" even when that should be impossible (e.g. a 2048x2048 image with 12 mips).

    upload_2019-2-8_10-18-54.png

    Any idea what this means?
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,448
    If you're referring to the "Some GameObjects are missing graphical elements" error in the screenshot, here is what I found, while quickly looking through the code.

    "Some GameObjects are missing graphical elements" means:
    • If a SpriteRenderer has no sprite is assigned.
    • If a MeshFilter/SkinnedMeshRenderer has no mesh assigned.
    • If a MeshFilter has no MeshRenderer on the same GameObject.
    • if a MeshRenderer/SkinnedMeshRenderer has no material.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    I'm not. I'm referring to the 0k (zero kilobytes) shown for all textures in the screenshot after the top two.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,448
    The ASTC texture format is just not handled in the code and then it reports 0 KB. Take a look at the GetBitsForPixel method.
     
    JoeStrout likes this.
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Aha! That's a pity, but it's also useful, since all my textures should be in ASTC — I need to take a closer look at the ones showing a size!
     
  8. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,005
    Hi,

    I've been working on related texture memory stuff in Unity and thought i'd make a quick update to the code here so that it fully supports the reporting of the correct memory size regardless of format types. It uses the native Unity methods to obtain the memory size via Reflection, the same methods that Unity uses to state the size in the Inspector preview window. As such this should now work correctly regardless of format type ( or changes to types in future by Unity ) and compression, including Crunch.

    I've only performed basic testing, but the changes are minor so it should work across platforms from Unity 5.6.7 upwards.

    However the original class was written quite some time ago and things have changed greatly in Unity since then. As such this code really requires a full rewrite to address various issues and more robustly deal with all the different texture types. It would also be nice to streamline the code into more classes. So while I can see that some information will be incorrect depending on Texture type ( e.g. mipmap count or getting depth for 3D volume textures ) the actual memory size reported should always be correct as it comes directly from Unity's own native methods.

    You can grab the new version from here
    https://gist.github.com/noisecrime/2f70b5d4ea827cb5965d38504ad1591c
     
    ilmario, Fibonaccov, nabergh and 2 others like this.
  9. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,458
    Thanks for that !

    I use this tool already ten years and its really nice!



    I'm getting some error when calculating:

    Material doesn't have a texture property '_MainTex'
    UnityEngine.Material:get_mainTexture()
    ResourceChecker:CheckResources() (at Assets/1. Okimika/ResourceChecker.cs:868)
    ResourceChecker:OnGUI() (at Assets/1. Okimika/ResourceChecker.cs:238)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
    Last edited: Nov 14, 2019
  10. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,458
    Can you make the mesh count buttons a bit larger?, the number does not fit in the button in my scene
    Or make the table fit to the window width.
    See screenshot

    Screenshot 2019-11-14 at 20.17.59.png
     
  11. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,458
    To make the buttons bigger I changed the width to 100 ( was 50 )
    +" GO",GUILayout.Width(100)
     
    Noisecrime likes this.
  12. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,005
    No problem.

    I wont be making fixes to this that don't directly relate to the code change for displaying the native Unity memory size.

    As mentioned the original code from github ( 2015 - 2017 ) is pretty old and I can see numerous issues with just the texture aspects, let alone anything else. So at this point I would say its better to rewrite it from scratch than trying to fix issues as they come up. Doing so would also allow you to make a much nicer looking UI too. Its on my to do list since i'm already writing some other Texture profiler utilities, but not sure when I'll find the time.

    As for making changes, you're best of doing what you did and changing the code yourself. The code has minor changes from the original so it should be pretty simple to update or just grab my new bits of code and back port to you own version. WinMerge is a great way of comparing two files.

    Having siad that I imagine replace line 868 with the following *should* address that error?
    Code (CSharp):
    1. if ( tMaterial.HasProperty("_MainTex") && tMaterial.mainTexture)
    However after a quick mess around I've been unable to cause that error, even creating shaders that don't use a _MainTex. Might be useful to post the shader/material that is causing that problem.

    Hope you understand. My main priority with this update was just to address getting reliable memory sizes.
     
    Last edited: Nov 14, 2019
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,458
    Code (CSharp):
    1. if ( tMaterial.HasProperty("_MainTex") && tMaterial.mainTexture)
    Yes this made the error go way!

    Thanks

    It happened only when I had "look in behaviour fields" on

    Yea don't worry about UI, I fixed the buttons sizes myself.
     
    Noisecrime likes this.
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    @Noisecrime, I hope you'll consider re-integrating your changes with the latest at handcircus version and submitting a PR. The handcircus one is still being updated — last change just a couple months ago — but still doesn't do memory size calculations your way (and I think your way is more correct). I found integrating your changes to be a little tricky since so many other things have changed since you forked.

    Thank you all for your efforts — this is such an incredibly useful tool, especially when developing for resource-constrained systems like Quest.
     
    ilmario likes this.
  15. EduardGames

    EduardGames

    Joined:
    May 14, 2013
    Posts:
    11
    Thank you, great work!
     
  16. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    42
    Damn this tool is so good for optimization, thank you very much!
     
    JoeStrout and Lars-Steenhoff like this.
  17. cmod

    cmod

    Joined:
    Mar 7, 2016
    Posts:
    2
    Cheers dude, thank you for this!
     
  18. RealitySims

    RealitySims

    Joined:
    Mar 4, 2014
    Posts:
    28
    Couldn't find which object was using a texture reported by another tool(there was an issue with it), this solved it in like 5 seconds.
     
    magique likes this.
  19. orimM123

    orimM123

    Joined:
    Apr 16, 2020
    Posts:
    1
    thanks ! amazing tool using for all my projects

    update: i cant build with this.
     
    Last edited: Mar 30, 2022
    Lars-Steenhoff likes this.
  20. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    179
    Thank you for your great work. I think it will be useful to avoid scene overload. Given, to work for a mobile game!
    On the other hand I have a question, we can know the weight, by decreasing of the objects of the scene, but can see those who are the most gourment and the most important to change (I would say to change necessarily for the necessity of the proper functioning of the game?) thank you
     
  21. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,300
    Great find, thanks a lot!