Search Unity

Significant FPS drop due to Culling

Discussion in 'Navigation' started by Gooren, Sep 18, 2017.

  1. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    Hi,

    I have noticed a significant frame drop (from 60fps to 42fps) when first enemy is spawned in our mobile game. This was on an Android device (Galaxy S4 i9506). So I checked the profiler and noticed a weird thing. The "Camera.Culling" row in the CPU section has doubled from 8ms to 16ms when enemy showed in the scene and it kept tanking our FPS until that enemy was destroyed.

    I double checked that we are CPU bottlenecked thanks to this issue. It was especially weird since we only use Frustrum culling in our game! Occlusion culling was not needed since our scenes are mostly wide open areas.

    So... before enemy spawn, Culling was eating less resources than Camera.Rendering, but after enemy got spawned, it ate AT LEAST 8ms extra!

    WHAT?

    Well, just a while ago I noticed that if I disable NavMeshAgent component on the enemy... the Culling performance cost is next to none. Even if I move the enemy by other means, Culling was untouched by it's existence!

    Then I enabled the NavMeshAgent component again and voila, CPU got destroyed by Camera.Culling again.

    This is probably a bug in Unity? Or am I missing something?

    PS: From my scripts, I only set the NavMeshAgent's destination once (yep, I checked that). And that is everything I do with it. Besides getting it's current velocity here and there.

    PS2: I am using Unity 2017.1.1p2

    Please help :(
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Can you show a screenshot of the profiler? I think you might be reading it wrong. If you think it is a bug it should be reported via the bug reporter. It's not something I've seen before.
     
  3. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    Sure,
    NavMeshAgent - Disabled: link
    NavMeshAgent - Enabled: link

    EDIT: If no one proves my profiler readings wrong, I will report this as a bug.

    EDIT 2: Now I have been able to measure even 4x increase in culling CPU time cost with just one enemy appearance in the scene.
     
    Last edited: Sep 18, 2017
  4. Gooren

    Gooren

    Joined:
    Nov 20, 2015
    Posts:
    332
    I just found the root cause of the issue. Apparently I overlooked that I am also using the NavMeshAgent's 'baseOffset' field to animate vertical hovering of my hover car enemies. And every frame this field gets changed, it causes humongous culling spike on the CPU.

    So... I will have to do it differently :(

    Well, one questions still remains. Is this culling spike caused by changing the baseOffset field value ok?