Search Unity

Cinemachine 2.2.8 problems

Discussion in 'Cinemachine' started by WorldFlickers, Feb 13, 2019.

  1. WorldFlickers

    WorldFlickers

    Joined:
    Sep 29, 2014
    Posts:
    7
    1. I need cinemachine to update via Update(). Now it allows only LateUpdate, FixedUpdate and so-called Smart Update (whatever it means). But for proper work of world-based canvases, I need to update Camera in Update() and then canvases in LateUpdate(). Just because of this reason I needed to copy all the plugin int Assets and use it - just for changing LateUpdate to Update in CinemachineBrain.

    2. In this version StateDrivenCamera doesn't switch off (gameObject.SetActive(false)) previous camera. I checked old version, and it has:

    public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
    {
    //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStateDrivenCamera.UpdateCameraState");
    if (!PreviousStateIsValid)
    deltaTime = -1;

    UpdateListOfChildren();
    CinemachineVirtualCameraBase best = ChooseCurrentCamera(deltaTime);
    if (m_ChildCameras != null)
    {
    for (int i = 0; i < m_ChildCameras.Length; ++i)
    {
    CinemachineVirtualCameraBase vcam = m_ChildCameras;
    if (vcam != null)
    {
    bool enableChild = m_EnableAllChildCameras || vcam == best;
    if (enableChild != vcam.VirtualCameraGameObject.activeInHierarchy)
    {
    vcam.gameObject.SetActive(enableChild);
    .......................

    and 2.2.8 has
    public override void InternalUpdateCameraState(Vector3 worldUp, float deltaTime)
    {
    if (!PreviousStateIsValid)
    deltaTime = -1;

    UpdateListOfChildren();
    CinemachineVirtualCameraBase best = ChooseCurrentCamera(deltaTime);
    if (best != null && !best.gameObject.activeInHierarchy)
    {
    best.gameObject.SetActive(true);
    ................

    and no gameobject.setactive(false) in entire plugin (related to state driven camera).
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    1. If I understand correctly, you need to update your canvases after the brain updates the camera. You can do this without changing brain.LateUpdate to Update. There are at least 2 ways:
    a) Do it in LateUpdate and set your script's execution order to happen after CM brain, or
    b) Hook into the Brain's CameraUpdated event, and update your canvases there

    2. If you want to disable the non-live vcams for performance reasons, you can set their StandbyUpdate property to Never.

    upload_2019-2-13_11-49-28.png
     
  3. WorldFlickers

    WorldFlickers

    Joined:
    Sep 29, 2014
    Posts:
    7
    thanks a lot
     
  4. WorldFlickers

    WorldFlickers

    Joined:
    Sep 29, 2014
    Posts:
    7
    upload_2019-2-15_13-50-35.png
    No, your solution doesn't work. As you can see, Standby update is set to "never" - and still several state cameras are active simultaneously.
     

    Attached Files:

  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    What do you mean "active"? You mean the game objects are active? That's ok - they are not being updated. I don't understand what the problem is.
     
  6. WorldFlickers

    WorldFlickers

    Joined:
    Sep 29, 2014
    Posts:
    7
    yeah, exactly. gameobects are active.

    I made my custom classes, where I subscribe on my custom input (for example, I want to realize input via network). And now I solve a task about switching between two states - near-to-ground 3d and over-ground top-down - via zoom. I subscribe _each_ state camera to input - and want to change zoom and handle "zoom limit" case _only_ on current active camera. Previously I just checked if a gameobject is active, and now seems like I suppose to check Core.Brain.ActiveCamera every time I want to change zoom. Or cache the state camera on state changed.
    And the point is that:
    1. in previous versions virtual cameras were being disabled on state change; and all the code that based on this feature is not compatible to the new plugin version
    2. in the beginning only current state virtual camera is enabled (at least in my project, which was originally based on previous plugin version), and then during lifetime all the cameras switch on and stay active - and it seems like sort of "unconsistent behaviour" - in my opinion, they should either switch on and switch off or stay active from the beginning.
     
  7. WorldFlickers

    WorldFlickers

    Joined:
    Sep 29, 2014
    Posts:
    7
    foreach (var z in zoomers)
    {
    z.OnMaxZoomReached += () => {
    if ((Cinemachine.CinemachineCore.Instance.GetActiveBrain(0).ActiveVirtualCamera as CinemachineStateDrivenCameraCustom).LiveChild == z)
    OnMaxZoomReached();
    };
    }

    something like this. to check if a camera is the current camera, I need all the
    (Cinemachine.CinemachineCore.Instance.GetActiveBrain(0).ActiveVirtualCamera as CinemachineStateDrivenCameraCustom).LiveChild
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Yes, you could do that, though you should add some suitable null checks in case you ever add any vcams to the scene other than the main SDC.
    There are other possibilities too.
    You could do something like y.ParentCamera.IsLiveChild(y), again with suitable null checks.
    Or, you could hook into the vcam's OnCameraLive event, and that way always keep track of the active vcam:

    upload_2019-2-15_9-10-0.png