Search Unity

CinemachineBrain.AfterPhysics() [Coroutine: MoveNext] Performance

Discussion in 'Cinemachine' started by ibbybn, Jan 31, 2018.

  1. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    It's a bit of a headscratcher for me lately. Takes about 2-10ms of performance.
    Goes up and down pretty wildly in the profiler.
    Have about 14 virtual and some freelook cams which i switch via changing priority in the scene.
    Is there a better way of switching the cams which is more performant? Turning the gameobjects on/off doesn't seem to make it better.

    Working with 2017.03 latest patch
    Using FixedUpdate Mode
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Is there any chance you could export this scene for me to look? 2-10 ms is way too much.
     
  3. bromanz

    bromanz

    Joined:
    Jan 30, 2017
    Posts:
    4
    I actually had a similar problem, but it disappeared after I restarted the unity editor. Since then I've not been able to reproduce it. I'll let you know if I'll bump into this again.
     
  4. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    We found a fix pretty quickly with gregory via pm. Mine was reproducable, and was likely to be a combination of too many vcams in a cpu/physics heavy scene. The best workaround so far is basically always having all vcam gameobjects off except the one we're using.
     
  5. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Can confirm this bug. Takes about 1000ms while using Unity's Recorder. Couldn't fix it no matter what.
     
    podwawel_ likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    FixedUpdate mode means that virtual cameras are updated every physics frame. If you're doing something (e.g. recording) that bumps up your frame time, you end up causing many more physics frames to be computed every frame, which if you have lots of vcams ends up taking longer, which causes more physics frames to be computed per frame... you get the picture.
     
  7. vverma9

    vverma9

    Joined:
    Jan 14, 2017
    Posts:
    6
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
  9. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    519
    Again same issue on our project, 2017.4 LTS, cinemachine 2.1.10

    upload_2019-6-19_13-43-3.png

    What can be done to troubleshoot ?

    Basically the camera is facing several hundreds of cubes and a unity terrain, that's basically it. One VCAM is active.
     
    Last edited: Jun 19, 2019
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Those numbers look way off.
    Can you give more details about your scene, like physics timestep, now many vcams, etc.
    Also: can you show image of your vcam inspector?
     
  11. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    519
    We're not using physics except for particles or other actions, but there are none at that time. Maybe you can give me some hints on how it behaves.

    The scene is not optimised as it is not the focus at the moment, quite texture heavy, lots of draw calls (several thousands) and tris (several millions)

    The Cinemachine Setup is as Follow
    Blend List
    -> 6 Cameras
    -> Last Is Active and is a StateDrivenCamera
    - -> 2 children
    - -> 1 Active a StateDrivenCamera Again
    - - -> 2 Children
    - - -> 1 is active a vcam. This vcam transform is following another object, the vcam itself has no active component (save during play is enabled)
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    What happens when you change your Brain update mode to LateUpdate?
     
  13. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    519
    The update mode was on "SmartUpdate" putting it to "LateUpdate" did not change the result, same for "FixedUpdate"
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    That doesn't make sense. Can you please show me the profiler (like you did above) when the Brain is on LateUpdate? I don't care about FixedUpdate for now.
     
  15. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    519
    My bad, I didn't look to the call list thoroughly or restarting the game maybe helped, in "LateUpdate" indeed the CPU spike remains but it seems, as I read it, that it now comes from our side, I'll do a deep profile :

    upload_2019-6-19_15-41-43.png
     
    Gregoryl likes this.