Sprite Atlas cannot reduce draw call

I have create a Sprite Atlas to batch the sprites
when i try to load the sprite Atlas from the resources folder
And save them into a dictionary

Then set the sprite of my spriteRenderers to the relevant sprite
one draw call is taken by each sprite

Then I tried to check from the frame debugger
It return object have different MaterialPropertyBlock set

Does anyone know why I got this?
Thank you

Here is my code

SpritesDictionary = new Dictionary<Id, Sprite>();
        SpriteAtlas = Resources.Load<SpriteAtlas>("MyPath");
        foreach (Id id in IdList)
        {
            SpritesDictionary .Add(id, SpriteAtlas .GetSprite(id.ToString()));
        }
MySpriteRenderer.sprite = SpritesDictionary [myid]

GetSprite should still reference the atlas so I’m not sure what is breaking your batching.

You should be able to reference the individual sprites as you normally would, and if they are assigned to the spriteatlas, they will be packed together and their materials will use the same texture. Is this dictionary fetching necessary?

Thanks for your response

I have tried to assign all the sprites to SpriteRenderer

The frame debug shows that they are in the same texture
but it still returns objects have different MaterialPropertyBlock set

Would it be possible to share a screenshot of the previous or following Draw Dynamic step of the Frame Debugger? This would make it easier to determine what in the MaterialPropertyBlock has changed between each step. Thanks!

Edit (did not see new post):
The atlased texture names look different from the first post and your new post. Are they both steps which are one after the other?

Do you mean screenshot like this?
The draw dynamic steps above these screenshots are other sprites

I have created 3 Sprite Atlas for 3 different kinds of sprites
So the name is different, sorry for if that misleading you.





Hi, yes, I do mean screenshots that are in order of rendering for the FrameDebugger, which you have provided. Thanks!

Based on the screenshots, each Draw Dynamic step does have a different MaterialPropertyBlock set where the _MainTex property has changed each step:

  • GreenPoint

  • Foods-8

  • FrogPor

  • Foods-8

  • FrogPor

It seems that each DrawCall is switching between two atlases, Foods-8 and FrogPor, for its texture? Is that the correct setup for your Sprites and SpriteAtlases?

These steps are only part of it or do you need me to show more screenshot?
There is another sprite atlas I didn’t show called LandMa
In the Frame Debugger, 3 of them are switching each other

Why is that happen?
Do I have to make sure that unity draw all Foods first
then draw the FrogPor and LandMa ?

Without knowing much about the Scene, it seems that the Sprites in the Scene are sorted in a way that the rendering is alternating between these two atlases. Dynamic draw call batching will not work if this is the case.

If you could show a screenshot of the Game View and identify the Sprites being rendered in the order shown in the Frame Debugger, that would be helpful. Alternatively, if it is easier, you could share your project as well!

Here it is





.





It seems that screenshot_7 and screenshot_10 should batch together
screenshot_9 and screenshot_11 should batch together

Could you share the Inspectors of the SpriteRenderers of the items shown in the screenshots? If they have the same sorting properties, like sorting order and layer, they should be sorted and ordered according to their material and be batched together. This would be as you have mentioned where 7 and 10 would batch together.

If you could share the version of Unity you are using, that would be great too.

Sorry for reply late
I am using Unity 2019.1.1f1

I have tried to open another scene
Load the sprite Atlas from the resources folder
Create lots of Sprite Renderer and
get the sprite from the dictionary the same way as you can see above
the draw call is only one

I have no idea why:(





Maybe it would be easier if you could post a (stripped down) project that Unity Technologies can use to reproduce the issue?

I think we would need to take a deeper look at your project in order to help you for this.

You can share your project by filing a bug with the Unity Bug Reporter with your project. Do post the case number here too, thanks!

If possible, you should have only the related elements in your project (Sprites, Sprite Atlas, the Sprite Atlas script etc).

Thank you for your help
I finally find out the problem from this post
the sprites shouldn’t be ordered in the same sorting order
forum.unity.com/threads/dynamic-batching-break-with-sorting-layer-and-order-in-layer.428046

2019.4.16f1c1
I have the same problem, and finally I resolve it by changing different sort order for each spriteatlas