I have a 2D game.
In Unity, it is recommended to place all images in a 2D atlas. This reduces the number of draw calls, reduces the load on the video system and increases fps.
And everything seems to be fine, but:
- It is recommended to use 1 atlas for each scene. Multiple atlases force Unity to switch between them, reducing performance and fps.
- When using any image from the atlas, the entire atlas will be loaded.
- If there are several atlases where the same images are loaded, when using these images in the scene, any of these atlases will be loaded (random selection).
As a result, problems arise. Here is a simple example.
I have images of trees and flowers. In scene 1 I need trees and flowers, in scene 2 only trees.
I decided to create 2 atlases.
In atlas1 I add pictures of trees.
In atlas2 I add pictures of flowers.
I load scene 2, where there are trees and flowers. Scene 2 loads 2 atlases. We get additional “video system load” because 2 atlases cause switching between them.
I decided to create an atlas for each scene.
In atlas1 I add pictures of trees and flowers.
In atlas2 I add pictures of trees.
I load scene 2, where there are only trees. Scene 2 loads atlas1 with trees and flowers. We get additional load because the atlas contains an image of flowers.
This happens because the tree prefabs in Image contain a link to the image of trees. The image of trees is added to 2 atlases.
Unity randomly chooses from two atlases and this time atlas1 was chosen.
What to do? Duplicate, copy images so that they are unique for each scene, create unique prefabs only for one scene - an extremely bad option.
This is duplication of images, prefabs, components…