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

Feature Request More sprite data in Inspector

Discussion in '2D' started by Lo-renzo, Oct 21, 2023.

  1. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,325
    It would be great if the sprite Inspector printed some informational data.

    d3 - Copy.png

    I'd like to be able to see a few numbers in the Sprite Inspector to aid optimization decisions, such as:

    1. how much empty space exists for the texture as a %, and as a % of the mesh [Should I pack this together with other sprites or crop the artwork's image?]

    2. vertex count because sometimes the sprite's mesh is enormously complicated or bad [Custom Outline?]

    3. a visualization of the sprite's mesh (kind of like wireframe mode - or at least like red line in pic above) to make sure it's not messing up royally, often because there's some accidental alpha somewhere that's creating more overdraw/vertices than is optimum

    I understand Sprite Atlases might make this complicated, but if it's in an atlas then ideally I'd like to be able to look at its generated preview and see the same info.
     
    Last edited: Oct 22, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,112
    Are you actually hitting vertex counts as your performance limitation?! This seems highly unlikely in 2023.

    On mobile hardware you're generally going to be pixel-fill limited (so overdraw is bad), not geometry limited, just as a rule of thumb.

    Otherwise... you know what I say about optimization:

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that you are gathering information at this stage. You cannot FIX until you FIND.

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Don't forget about the Frame Debugger either, available right near the Profiler in the menu system.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.

    "Software does not run in a magic fairy aether powered by the fevered dreams of CS PhDs." - Mike Acton
     
  3. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    150
    Code (CSharp):
    1. [MenuItem("Tools/Test Vertex Counts Of Sprites")]
    2.         static void TestVertexCountsOfSprites()
    3.         {
    4.             var sprites= AssetDatabase.FindAssets("t:sprite", new string[] { "Assets/Sprites" });
    5.             for (int i = 0; i < sprites.Length; i++)
    6.             {
    7.                 //you should probably add cases for "sprite mode: multiple" etc.
    8.                 var vertexCount = AssetDatabase.LoadAssetAtPath<Sprite>(AssetDatabase.GUIDToAssetPath(sprites[i])).vertices.Length;
    9.                 if(vertexCount>4)//magic number, convert to a constant field etc.
    10.                 {
    11.                 Debug.Log(AssetDatabase.GUIDToAssetPath(sprites[i]) + " has " + vertexCount);//no need to optimize this, we aren't hoping for a lot of sprites to have giga vertex count
    12.                 }
    13.             }
    14.         }
    something like this should work I guess(I haven't tested the code)

    The problem would be that this takes too much time if you have lots of assets.

    In that case, you are going to want to test vertex count when a sprite is processed(happens when you change import settings, force re-import, import new sprite) but asset post processor doesn't give much control over the final sprite.
    • What you'll want to do is, save the asset's path to an external file or a scriptable object, and add a new menu item to check only the new sprites instead of all sprites in "Assets/Sprites" path. I guess you could also automate this to happen every time you enter play mode??
    OR
    • Find a clever way of executing a method after asset post processor is complete