[Unity]Too many drawcalls for miniMap

Started by
9 comments, last by achiga 4 years, 5 months ago

Hi folks,

I am currently working on implementing a minimap for our FPS game. We have roughly one hundred players needed to be shown on mini map for observation mode. The icons are using the same sprite with different colors and texts(set with code). The texts can not overlap with each other. So I just assigned different depth values to different icons. But that caused more than 100 drawcalls. I am wondering if there is any way to improve it.

Advertisement

I know that drawcalls of meshes with same material can be batched. However, in my case, I set texts on each sprite(UILabel), it seems that batching is broken by this action. But I need texts stay exactly on the top of the corresponding icon. Any ideas to reduce the drawcall? 

 

Update:

The same issue seems be here : http://www.tasharen.com/forum/index.php?topic=15517.0

How are you displaying the sprites? Are you using Unitys UI system (UGUI), or are you using something else? (The linked thread uses NGUI.)

What do you means by "assign different depth"? Unity UI doesn't offer to set a depth, but only a z-value on the transform, and an order in layer value.

17 hours ago, Sacaldur said:

How are you displaying the sprites? Are you using Unitys UI system (UGUI), or are you using something else? (The linked thread uses NGUI.)

What do you means by "assign different depth"? Unity UI doesn't offer to set a depth, but only a z-value on the transform, and an order in layer value.

I'm using NGUI to display the sprites. So the order of rendering all the sprites are based on depths instead of z-values. It seems drawcall batching is broken since sprites and labels have adjacent depths but they are using different textures.

Does the batching work as expected...

  • ... if you assign the same depth value?
  • ... if you assign the same sprite (from the same texture/atlas)?

To be honest, I didn't work with NGUI enough. Is the project on the other hand old enough to "justify" the decision for NGUI and against Unitys UI system (UGUI, the new one)? I'm not absolutely certain about it, but it seems like you might end up having a better development using UGUI since it's used by far more people nowadays.

1 hour ago, Sacaldur said:

Does the batching work as expected...

  • ... if you assign the same depth value?
  • ... if you assign the same sprite (from the same texture/atlas)?

To be honest, I didn't work with NGUI enough. Is the project on the other hand old enough to "justify" the decision for NGUI and against Unitys UI system (UGUI, the new one)? I'm not absolutely certain about it, but it seems like you might end up having a better development using UGUI since it's used by far more people nowadays.

Thank you for reply.

  1. Yes, as long as I assign the same depth value to the sprites and another value(either higher or lower) to the labels. The batching works as expected.
  2. I have not tried to use the same texture/atlas but I believe that works. However, this workaround would take more time since we need more art resources.

The project has been for more than 3 years. They had to use NGUI at that time and did not have a chance to migrate to UGUI. So we have to work on NGUI for now. And there are few tutorials and references about NGUI online nowadays, which blocks the development sometimes. 

1 hour ago, achiga said:

I have not tried to use the same texture/atlas but I believe that works. However, this workaround would take more time since we need more art resources.

This was not a suggestion to solve the Issue, but to investigate it. If there is no batching even for the same texture/atlas, then either there is a bug in NGUI, or there is no way to batch across multiple depth values.

1 hour ago, achiga said:

The project has been for more than 3 years.

That's actually what I was afraid of: a project started a long time ago. Depending on how long you're supposed to support this game, you could on the one hand just do a simple and stupid solution (even if it's not the most elegant one), or on the other hand slowly replace the entire UI by UGUI (if the project is still developed on and is supposed to be continued for a long time).

11 hours ago, Sacaldur said:

This was not a suggestion to solve the Issue, but to investigate it. If there is no batching even for the same texture/atlas, then either there is a bug in NGUI, or there is no way to batch across multiple depth values.

That's actually what I was afraid of: a project started a long time ago. Depending on how long you're supposed to support this game, you could on the one hand just do a simple and stupid solution (even if it's not the most elegant one), or on the other hand slowly replace the entire UI by UGUI (if the project is still developed on and is supposed to be continued for a long time).

Thank you for your suggestion. I will take a look at that. Perhaps we should start to think about moving to UGUI since our game is still in development.

In unity there is a draw call for each image you access, so putting all your images in a single file will greatly reduce the amount of draw calls, I didn't know how much a difference it makes before optimizing one of my projects. I pooled every object in my game and I didn't get as much as a performance increase as when I put all my sprites in one atlas. It is a big pain to reassign sprites all the time if you are still creating art.. there are solutions tho, there is atlasing software which works, but I did notice a big dip in quality.. I was going to try to write a script that keeps references to all my sprites and see if that works.. but not sure if it's possible with prefabs and stuff.

On 11/21/2019 at 7:50 AM, logicandchaos said:

In unity there is a draw call for each image you access, so putting all your images in a single file will greatly reduce the amount of draw calls, I didn't know how much a difference it makes before optimizing one of my projects. I pooled every object in my game and I didn't get as much as a performance increase as when I put all my sprites in one atlas. It is a big pain to reassign sprites all the time if you are still creating art.. there are solutions tho, there is atlasing software which works, but I did notice a big dip in quality.. I was going to try to write a script that keeps references to all my sprites and see if that works.. but not sure if it's possible with prefabs and stuff.

Putting all the sprites into the same atlas definitely works. I finally ended up writing a new class which inherits NGUI UISprite class with icons as background and numbers on the top of it. By using sprites of background and numbers from same atlas, all the drawcalls are batched into a single one.

This topic is closed to new replies.

Advertisement