Search Unity

static batching not working with lightmapped objects?

Discussion in 'General Graphics' started by IgorAherne, May 29, 2018.

  1. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Hello,

    I am trying to understand how the Frame Debugger works, with Static Batching.

    It seems to avoid batching two objects that use the same material, are both static and are using the same lightmap texture.

    Please note, I am using GPU instancing for most objects:
    isntancing.JPG

    Please have a look at the screenshot, each half shows the stats of "pole_03 (6)" and "pole_03 (2)" respectively.

    "A"
    shows second pole is selected in the hierarchy, "B" is the Unity's reason, "C" shows that lightmap is actually the same ...Doesn't static batching work with lightmaps?

    static batching0.jpg

    Not sure if it made difference, but I've baked lightmaps after marking all the objects as Batch Static

    ---------------------

    From what I understand, the only static batches I am getting are shown as "Static Batch" in the hierarchy (at the bottom), and all other elements above them are not batched :( For example:
    • Draw Mesh mobile_pole_03 (6) <--not batched, drawn separatelly (even if has GPU instanced material)
    • DrawMesh mobile_pole03 (2) <---not batched, drawn separatelly
    • Draw Mesh dead_tree_01_a_trunk <--not batched, drawn separatelly
    • Static Batch <---some objects were batched
    • Static Batch <---some objects were batched

    Is this correct? Also, lightmaps (Non-directional) and static batching are not allowed together?
    I am using Deferred Rendering, iOS Metal, Unity 2017.1
     
  2. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    We Have exactly the same problem, I read in manual, that objects are batched by instancing together if lightmaps are the same, but it dont work, even if lightmap atlas are the same unity wont batch it together. Why it is like that if manual says it should work.
     
  3. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    EDIT (removed what I wrote in this particular post)

    I received a reply from unity support. Static batching is designed to only work during Play mode.
    It won't work unless you are actually playing the game in editor.

    Hit play, and it should be working
     
    Last edited: Mar 25, 2019
    Kennai and jrumps like this.
  4. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    Thanks fgor reply. but I'm talking about GPU Instancing, it just font work if lightmap static is check on objects. according to unity manual is should, but it still gives info taht cant bathc because "object arelightmapped" I'm using the same lightmap atlass for that objects. (I dont want to use static batching cause it doesnt support LOD, and GPU instancing is supporting that and dont add memory.)
     
  5. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    I hope someone from @Unity could answer that it would be great to hear official statement :)
    Regards
     
  6. meti3141

    meti3141

    Joined:
    Feb 21, 2020
    Posts:
    2
    Hi guys
    I have a similar problem with my project right now. Does anyone have any fresh information on this?
     
  7. kotoezh

    kotoezh

    Joined:
    May 21, 2013
    Posts:
    21
    Hi. In my particular case the reason of static objects were not batched was in the script which disabled groups of objects OnAwake(). And then after they were enabled with a player triggered event they were not statically batched with message "objects are lightmapped".
    To fix it I moved initial disabling in OnStart instead of OnAwake - it works properly.
    So it seems objects are collected into a static batch after OnAwake but before OnStart, and all of your static objects should be enabled in this period to be included in batching.
     
  8. Gluttonium

    Gluttonium

    Joined:
    Aug 19, 2021
    Posts:
    31
    Well hey there, I read this post and it completely changed my view on how the static batches get prepared but I do wonder, how did you find this out? Is there a source or was it by happenstance?