Mad Level Manager is written with performance in mind, but there are some bottlenecks that user can easily fall into. Here you will learn about optimization tricks for Mad Level Manager.

Level Select Screen Performance

Mad Level Manager uses rendering engine called Mad2D. Its biggest issue is that it doesn’t support texture atlases (yet), but instead it heavily depends on Unity dynamic draw call batching optimization. It’s not really an big issue, but you need to know that batching may fail if you prepare your scene in a way, that will force it to fail (no way!). Here’s the explanation:

Mad2D draw engine is drawing all sprites in order determined by GUI depth. Sprites with higher depth will be drawn above sprites with lower depth. What about if two sprites have the same depth? They will be rendered in unspecified order. These are the basics.

Unity3D dynamic batching optimization merges many objects draw calls into one, on condition that they are next to each other. The easiest way to understand this is through an example.

Counting Draw Calls

Let’s think of a scene, where Mad2D will order sprite rendering in this order (there are two textures):

In this scenario minimum draw call count is 6. That’s because each rendering procedure needs to change the rendering context – the texture. Changing the context means additional draw call. Simple?

Here draw call count is equal to 4. Thats because first two hearts can be painted using one draw call, next two slots is another draw call. Last two icons will generate two draw calls, because they are different. That’s 4 in total.

This is the best possible configuration, because three hearts can be merged into one, as good as three following slots. Number of draw calls here is 2.

Level Icon Configuration

This knowledge can be applied to how you should configure your level icons. Icons are built of several sprites, so it’s very important to set GUI depths that will allow batch optimization when drawing multiple icons on the same scene.

If you’ll configure your icon as above, then no matter how many icons there will be on your level select screen, all background will be drawn in just one draw call. The same applies to level numbers, lock icons, and stars. If you’re placing other sprites than icons on your level select screens, remember to not pollute these GUI depth values, because it may break the batching process to smaller chunks.