Search Unity

Something break sprite batch draw calls again in Unity 4.5.4

Discussion in '2D' started by ajordanwang, Oct 10, 2014.

  1. ajordanwang

    ajordanwang

    Joined:
    Oct 10, 2014
    Posts:
    2
    Hello there,

    We are making a 2D game with Unity 2D features. In this project, we link multiple game objects into a hierarchy to model a simple human skeleton in Unity. Most of these game objects have a SpriteRenderer. All sprite assets used by these SpriteRenderers were given a specified Packing Tag 'Hero'. And we've turned the Sprite Packer Mode to 'Always Enabled'. However, we still get more than one draw call at the runtime. We've checked that all sprites have been packed into the same atlas generated by Sprite Packer. Although, we've found 2 tricks can get less draw calls(talk about them later), we want a reliable soulution from Unity to tell us how to get one draw call in our situation(where all SpriteRenderers use the same material 'Sprites-Default' and all sprite assets have been packed in the same atlas).

    Following steps can reproduce the problem.
    1. Create a new 2D project with Unity 4.5.4f1.(We've tried 4.5.2/4.5.3, all versions have this problem). It's no matter to set the platform as PC Windows or Android.
    2. Turn the mode of 'Sprite Packer' to 'Always Enabled' with menu Edit->Project Settings->Editor.
    3. Import our package 'SpriteDrawCalls.unitypackage' in the attachment, and open the scene 'Test'.
    4. Run the game and check the Stats in the Game view. There should be about 8 draw calls for our character 'Hero'.
    Furthermore, we've found 2 unreliable tricks to get less draw calls. Mention them just for your information.
    1. At the runtime, open the Profiler window, find the sprites which have been shown under SpriteRenderer.RenderSingle. To randomly adjust the 'Order in Layer' of their SpriteRenderers can reduce the draw calls. For example, the 'Shadow' sprite in the attachment picture, we set its 'Order in Layer' from 0 to 2 at the runtime. The draw calls will be changed from 8 to 7.
    2. Assign a trivial transparent sprite to all SpriteRenderers which has no sprite asset set in the prefab. Then run the game, the draw calls will also be reduced observably.
    So, we think there must be something break the sprite batch draw. It might be a Unity bug. Please give us some hints. Thank you very much!
     

    Attached Files:

  2. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    Just to add on to this in case it's related to the same bug, I'm having two sprite batching problems in 4.5.5f1. I have 7 sprites with identical settings that I pack into a single atlas using a consistent packing tag. The only difference is that one of the source textures is 256x512 instead of 256x256 like the others.

    Problem 1: The 256x512 never batches correctly. Each additional sprite renderer creates an extra draw call. GameObjects are scaled at 1,1,1 up the parent chain. I've tried moving them around in the scene, changing their Sorting Layer and Order In Layer, etc.

    Problem 2: The 256x256 sprites only batch correctly if I give them all a non-zero Order In Layer. Just setting that to 1 makes them all batch correctly, for example. Otherwise, each sprite renderer creates a draw call.
     
  3. ajordanwang

    ajordanwang

    Joined:
    Oct 10, 2014
    Posts:
    2
    All my atlases are square, so I never met your first problem. And the problem 2, according to my first post, I think even if you give all of them non-zero values, you could still get several draw calls. Check out my attachment with my first post. I give every sprite a non-zero order value, but still get more draw calls.
     
  4. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    My atlas itself is 1024x512 and contains all seven sprites, but maybe I should try a square one. Mainly I pointed out problem 1 because it could be related to what you're experiencing -- I've tried changing all those settings and nothing has made batching work.