Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by eviltenchi_84 · Dec 06, 2013 at 08:58 PM · editorspriteoptimizationbatching

Sprite batching

So, I have a scene setup with lots of different sprites using the new 2d system. Most of the sprites are single and not from atlases. When I hit play, I have a crazy amount of draw calls. The odd thing is, if, while playing, I disable a chunk of sprites and then re-enable them, all of a sudden they are now batched and the draw calls drop. My question is, how come they are batched only after I disable and re-enable them?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eviltenchi_84 · Dec 10, 2013 at 06:22 PM 0
Share

nobody has any input?

avatar image Sundar · Dec 10, 2013 at 06:30 PM 0
Share

Ins$$anonymous$$d of disable / enable gameObject, use renderer to do the same, like

renderer.enabled = false;// or true;

avatar image eviltenchi_84 · Dec 11, 2013 at 02:02 AM 0
Share

I don't want them disabled though. I just am confused on why the batching occurs only after a disable and re-enable

avatar image shopguy · Mar 30, 2014 at 08:41 PM 0
Share

Did you ever figure this out? Seeing same issue. I think I might be related to using the "Sprites-Default" material for all sprites even though I have 3 different sprite textures (in my case I am using atlases, 3 @ 1024x1024), but not sure yet.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by shopguy · Mar 17, 2015 at 05:47 AM

Old question, but no answer, so...

Sprite batching is related to drawing order, which in 2D world is a combo of your sorting layers and Z position. I'm guessing you have several (maybe all) of your objects with the same sorting layer and Z position, so Unity ends up drawing them in a seemingly random order (sometimes you'll notice overlapping sprites "flicker" in this case, as one is drawn first on some frames, and the other on other frames).

When you disable/re-enable, it changes the order Unity is drawing your sprites. So depending on which ones you enable/disable, you will see different results, and the results can be huge variances. Take for example, 2 sprites using 2 different textures:

Sprite A = texture 1 Sprite B = texture 2

If you have a 100 of each sprites, and Unity draws Sprite A, then Sprite B, then Sprite A, then Sprite B.. over and over, for each 100, you will end up with 200 draw calls. If Unity draws all of Sprite A first, then all of Sprite B second, you will have 2 draw calls.

This can get very difficult to manage in certain scenarios and become very complex in a hurry. For example, 2.5D games can be very tricky, as things need to be drawn in a specific order to fake 3D (lots of overlapping). If you try to share parts of your sprite sheets... say you have 10 characters all with the same eyes, so you try to share the same eyes from a single sprite sheet for all of those characters, but mix in other parts from other sprite sheets. If you draw eyebrows first (from sheet A), then eyes (from shared sheet), then face (from sheet A again), you get 3 draw calls, instead of 1.

The only really simple way to handle that I have figured out:

  1. Have everything on 1 huge sprite sheet -- not practical unless you are doing pixel-art or low-res games.

  2. Have all copies of the same sprite use the same Z order, always. So if you have a "spider" in your game, all spiders have the same Z order (or sorting layer), or at least don't have any other sprites "in between" them. This is what I usually do, but can be a pain to setup scenes this way, without writing some editor scripts to help.

  3. Probably their are some assets/libraries to help -- never tried any.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to force static batching being performed at runtime? 0 Answers

Is it possible to batch textures that are Read/Write enabled? 0 Answers

What's the use of static batching? 0 Answers

Frame Debugger: GPU Instancing/batching, Why does Unity choose to draw random objects in between batches of an instanced object? 1 Answer

Multiple instances of static mesh increase size of game build 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges