Search Unity

Question Batching sprites from "cell" prefabs which are instantiated at runtime is not working properly..?

Discussion in '2D' started by Valynna, Dec 20, 2022.

  1. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    https://forum.unity.com/threads/do-sprites-created-during-runtime-get-saved-by-batching.843508/

    According to this thread with an official response (best source I could find), if I understand it right, all sprites with a shared material will be batched together.

    Okay cool.

    So what I'm doing is making a large maze-like structure by instantiated a lot of "cell" prefabs (with 6 walls and 6 connectors each, along with 6 wall shadows and 6 connector shadows. The shadows and connectors have different materials). In a typical game world, there are 319 of these cells.



    It seems like, I'm getting ~400 draw dynamic (draw calls) on the mini-map camera, and ~580 draw dynamic (draw calls) on the main camera.

    Obviously since these walls and decorations and what not are never moving, I really think there should be some kind of way to batch them all at once.

    I've tried a few solutions, mostly including the StaticBatchingUtility.Combine(root); command. Sometimes I run it on the "game" object which is the parent object of everything, and sometimes I take all of the wall sprites or all the connector sprites or whatever and put them as children of a new root object and run it like that, but no matter what I do - I'm still getting hundreds and hundreds of draw calls - even though all of the walls, shadows, connectors, connector shadows, etc... all share the same material!
     
  2. Valynna

    Valynna

    Joined:
    Apr 1, 2021
    Posts:
    39
    Not sure if it matters, but these are static objects that I'm trying to batch here... and the prefab is marked to 'static' as well as all the children of that object (all walls, connectors, wall shadows, connector shadows, etc)