- Home /
Same Sprite in multiple sprite atlases breaks dynamic batching
I use the same sprite in two sprites atlases for dynamic batching in different situations, but unity always uses the same (first) atlas. Because of this dynamic batching breaks in the second scenario. I dont want to import the same sprite twice and all the sprites in the same atlas is too big. Does anyone have an idea how to achieve dynamic batching in both situations?
EDIT:
First I import the sprite sheet (smoke animation) and cut it with the sprite editor (different smoke states as separate sprites). Then I use the sprites in my scene. After that I create a sprite atlas and add all sprites of the scene that should be batched together (smoke sprites, cactus sprite and so on). This works without any problems.
In a different situation I also need the smoke animation. Because of that I create a new sprite atlas (cannot use the first one, because of the size) and add the smoke sprites with some other. But batching doesn't work here, because unity uses the wrong atlas for the smoke sprites: First the right atlas is chosen. Then unity switches the atlas because of the smoke sprites. After that unity uses the right atlas again.
I know that i could optimize the scene with a different order of the sprites. Nevertheless there is one extra draw call for the smoke animation.
Answer by Robo648 · Jan 11, 2018 at 09:51 AM
None have a solution? Is it possible to import the same image twice? I don't want to switch the sprite in multiple folders if something changes.
Answer by creganjordan292 · Jan 11, 2018 at 10:05 AM
I'm unsure why you would want to waste texture memory by storing the same sprite twice, as an extra draw call doesn't really hurt much. Either way, the reason why dynamic is breaking is because you have two different sprite objects, with two different references. You need to switch between them (more overhead) when you switch sprite sheets.
Do you have an idea how to use the same sprite in two atlases? All visible objects are from the same atlas and just for one sprite unity changes the atlas (breaks batching), because the sprite is also in the second one. I don't understand why unity doesn't check if the current atlas also contains the sprite.
Because the reference for the sprite is still pointing to the original atlas, you need to tell unity to use the other sprite, as it doesn't know it's the same sprite.
How can i do that? Currently I put the sprite to the renderer and after that I add it to both atlases.
Your answer
Follow this Question
Related Questions
Batching to IOS not working ??? 0 Answers
U4.6 - How to use individual sprites from an atlas in script? 1 Answer
How to set Sprite Atlas Variants active ? 0 Answers
Sprite batching 1 Answer