Search Unity

Manually update camera position

Discussion in 'Cinemachine' started by lordzeon, Mar 18, 2020.

  1. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    Hi!, i´ve discovered cinemachine after making my own basic implementation, i was surprised by it, so i´ve ported it but im having some issues. My app uses timelines to make animations and render them to video, when it can go beyond the FPS required for the video record, the time is advanced to the correct timeline position (if app can run in 120fps and the video is 30fps, then it would take 1/4 of the time to render), the problem with this is that every update on my app is done outside update methods, with cinemachine the video outputs are popping if i use any damping either in move or aim, which is the point of using cinemachine for this, the problem can be reproduced in the timeline, if you use 2 blended cameras, then pause the timeline during the blend (or even without blend when there is damping), the camera won´t pause, and that is what i expect, otherwise when you hit play, the camera won´t be where you need. There is any form to archieve this?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    If I understand correctly, you have some code that manually advances the timeline and renders the frame? The problem is likely the discrepancy between the deltaTime reported by Timeline, and the 1/30 deltaTime that you are using to render.

    There is a static
    CinemachineCore.UniformDeltaTimeOverride
    which you can set to be 1/30 when you are rendering. This will force CM to use that deltaTime for its damping and blending calculations.
     
  3. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    Hi Gregor!, thanks for answering, yes, i do have a custom timeScale, my hack was to create a MyCameraBrain using CameraBrain as Base, changing the LateUpdate Method with this line:

    Code (CSharp):
    1.            
    2.  if (manualUpdate)
    3.             {
    4.                 UpdateVirtualCameras(CinemachineCore.UpdateFilter.ForcedLate, AnimationsManager.GetTimeOfCurrentProgress() - lastTime);
    5.                 lastTime = AnimationsManager.GetTimeOfCurrentProgress();
    6.             }
    7.  
    of course this is too hacky to feel good about it and i had to create the bool value because doing
    public new UpdateMethod m_UpdateMethod = UpdateMethod.ManualUpdate;
    works but with error because of double Serialization.

    Can you give me a basic example for implementing
    CinemachineCore.UniformDeltaTimeOverride
    ??
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Sure. Take out the brain hack, and in your AnimationsManager, put
    CinemachineCore.UniformDeltaTimeOverride = currentProgress - lastFrameTime

    Do it every frame, before CinemachineBrain.LateUpdate runs.
    When you are finished all the frames, set
    CinemachineCore.UniformDeltaTimeOverride = -1


    CinemachineBrain will use this value, if non-negative, as an override for deltaTime.
     
    samochreno likes this.
  5. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    That solution is elegant! but CinemachineCore dont have UniformDeltaTimeOverride field... neither the instance... i am missing something? im using version 2.1.10
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    That is very old!
    We've just released 2.6.0-preview.2
    Get the latest from the package manager.

    If you've installed Cinemachine from the asset store, you must delete it from your project assets (also delete CinemachinePostProcessing, if you have it) BEFORE you install from package manager. That is very important, or the upgrade won't work properly. It's also best to open an empty scene when you do this.
     
  7. lordzeon

    lordzeon

    Joined:
    Jun 1, 2018
    Posts:
    44
    After my message i see the advice in the asset store, it works like a charm... i really thank you for your help and the amazing tool.
     
    Gregoryl likes this.