How can i reduce draw calls in 2d urp?

Hello.
After getting a lot of information through the Unity forum, I started developing it.
thank you

Searching at first I saw a simple way to lower the draw call through a sprite atlas.
However, when I use mat.SetFloat as a script, the material becomes an instance, and the draw call increases.

What I’ve found since then is GPU Instancing.
But it still feels difficult to me!
The original shader was created through shader graph, but was rewritten as shader code to enable GPU Instancing.

And it says that you can use Mpb, but I don’t understand how it should be connected.

MaterialPropertyBlock Mpb = new MaterialPropertyBlock();
Mpb. SetFloat(Flash, 0f);
GetComponent<SpriteRenderer>.SetPropertyBlock(Mpb);

Is the same way correct? But it doesn’t reduce draw calls.

As a result of checking with the Frame Debugger, it was rendered from the top.

207393-11.png

Is it because of the settings for 2d sort?

It may sound strange by turning the translator, but thank you for reading.

@dhshin05 - Draw calls can indeed be reduced using a Sprite Atlas. However, an increased number of draw calls while using mat.SetFloat is because each instance of the material gets its own draw call.

GPU Instancing:

GPU Instancing can be helpful in reducing draw calls but it can be complex, especially when used with Shader Graph. If you’ve already rewritten your Shader Graph shader into code to enable GPU Instancing, you are on the right path.

Using MaterialPropertyBlock (MPB):

As for MaterialPropertyBlock, it allows you to modify properties of the material instance without creating a new material. It can indeed help you reduce draw calls when you have multiple objects with the same material but slightly different properties. You can set these different properties via MPB.

Looking at your code:

MaterialPropertyBlock Mpb = new MaterialPropertyBlock();
Mpb.SetFloat(Flash, 0f);
GetComponent<SpriteRenderer>().SetPropertyBlock(Mpb);

It seems correct assuming “Flash” is a valid property of your material. However, please ensure you’re setting the property block for all instances of your material which need the property to be modified.

2D Sorting:

Sorting in 2D shouldn’t typically affect your draw calls, it affects the render order of the objects in your scene. If your draw calls are not reducing, it might be due to some other factors rather than 2D sorting.

GetPropertyBlock:

As for your question about using GetPropertyBlock before SetFloat, yes, typically, it’s a good idea to use GetPropertyBlock before modifying and setting it. The reason is that GetPropertyBlock fetches any existing values on the material instance. Otherwise, any modifications made to the property block will be lost. So you might want to modify your code as follows:

MaterialPropertyBlock Mpb = new MaterialPropertyBlock();
GetComponent<SpriteRenderer>().GetPropertyBlock(Mpb);
Mpb.SetFloat(Flash, 0f);
GetComponent<SpriteRenderer>().SetPropertyBlock(Mpb);

Remember to replace “Flash” with the actual property name you want to modify.

I hope this helps! Feel free to ask if you have any more questions.