Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Cinemachine frame drop.

Discussion in 'Cinemachine' started by Brother_77, Oct 7, 2023.

  1. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    Hi
    I use multiple cinemachine cameras, but only one at a time is enabled, and get random frame drops, and after analysing the "build and run" it seems the cpu is processing 11 ms on cinemachine per frame !

    I could not understand the profiler output, any suggestions would be much appreciated

    I am on Unity 2022.3.7 and Cinemachine 2.9.7 and main camera is freelook that has these framedrops. Also there is an overlay camera for UI that runs separately from Cinemachine brain, with regular Unity Camera set, could that be the issue ? If so what is the correct way ?

    cinemachine.png
     
    Last edited: Oct 7, 2023
  2. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Heyyoo :)

    What happens if you remove all cinemachine components from your scene? PostLateUpdate.FinishFrameRendering is a URP call not cinemachine.
    What's your draw call looks like? You could see that in the stats window of the game view (A screen shot would help if you can).
    Also could you save the profiling data (Top right of the profiler window) and send it to us?

    Let us know
     
    Brother_77 likes this.
  3. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    What happens if you remove all cinemachine components from your scene? PostLateUpdate.FinishFrameRendering is a URP call not cinemachine.

    No cameras are rendering and the frames seem good. Also it is an URP call but the child calls (RenderSingleCameraInternal etc ) are referencing the Cinemachine ?

    What's your draw call looks like? You could see that in the stats window of the game view (A screen shot would help if you can).
    stats.png

    Also could you save the profiling data (Top right of the profiler window) and send it to us?

    Tried attaching it, same as image but the file extension is not supported ? Where should I email it to ?



     
  4. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    From what I have seen, your project is GPU bound. Which means something is pumping all your resources on the GPU.

    You can see that with a high GFX.WaitForPresentOnGfxThread.
    Screenshot 2023-10-10 at 2.49.22 PM.png

    Now the question how do you fix that? You might need some trial and errors to find what's wrong.
    From what I have seen it's not your meshes. 100k triangles and 250 batches is a very low value.

    However there is this that stands out. Is your project using camera stacking in any way?
    https://docs.unity3d.com/Packages/c...es.universal@17.0/manual/camera-stacking.html
    Screenshot 2023-10-10 at 2.51.08 PM.png
    Could you try to disable it and see what happens?
     
    Brother_77 likes this.
  5. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    Thank you!
    I previously had regular cameras with a camera stack of an overlay camera for rendering UI particle system.

    Now:
    The main camera I turned it into a CinemachineBrain, without removing the stack ? Would this interaction of regular cameras with Cinemachine could cause such unwanted frame drops ? It shows a warning. If I remove it where should I stack it ? As my new main Cinemachine camera is - Freelook, but it does not have an option to stack? Also I switch between other virtual cameras occasionally, but this particle system needs to be constantly available, regardless of Cinemachine camera status.

    camera stack.png

    (Also there is separate UI Canvas with Screen Space Overlay, but I would assume it does not have any effect on this)
     
  6. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Can you show us the full inspector of the image you posted? To be completelly honnest I don't know how stacks works would help me reproduce your issue.
     
    Brother_77 likes this.
  7. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
  8. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    If you over the warning on the overlay camera is there a tooltip? What is it saying?
     
  9. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    So initially I had a camera stack on my main camera which I turned into a CinemachineBrain and then a warning showed on the stack field and it offered a fix which I selected. Now a regular camera, not a Cinemachine camera is set as overlay and stacked on CinemachineBrain, is that fine ? Or does the stacked camera has to be from Cinemachine package ?

    I compared the profiler with and without camera stacked and there is a performance hit, and the smoothness of the camera does feel not as good if without the stack ?

    No stack:
    nostack.png

    Stacked:
     

    Attached Files:

    Last edited: Oct 20, 2023
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Cinemachine is only a system to procedurally animate the camera's transform and some of its lens properties. It does not impose any restrictions on the camera system or on how you can combine the Cinemachine-animated cameras with other cameras. Think of it as a complicated script to animate an object.
     
    Brother_77 likes this.
  11. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    So the overhead created by camera stack in the profiler provided is expected ? And not to worry ? It seems it impacts the smoothness of camera
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Does the overhead occur if you disable the CM brain?

    Also important when testing framerate and smoothness in Unity: do it in a build, not in the editor. Editor introduces lots of spurious overhead. And if you MUST do it in the editor, minimize the number of open views and make sure no inspector is visible.
     
  13. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    Yes the profiler images I added above are from development build with autoconnect profiler on a device. Cinemachine is taking 30 % of player loop, and when the camera stack is used it seems the smoothness of camera is affected, I do not understand the profiler much and so am confused. sorry
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Does the overhead occur if you disable the CM brain?
     
    Brother_77 likes this.
  15. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    I disabled CM and used regular camera with a stack and Overlay is only taking 1ms, so it seems its better.

    Tested on device with development build and autoconnect profiler
     

    Attached Files:

  16. Brother_77

    Brother_77

    Joined:
    Feb 8, 2019
    Posts:
    226
    I think I provided render thread instead of main and there still is similar overhead as CM, I dont know then, there is a massive Gfx : Semaphore.Waitforsignal which means the graphics is waiting for other thread to finish, but how do I find which ?
     

    Attached Files:

  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Brother_77 likes this.