Search Unity

Bug issue when blending cinemachine cameras

Discussion in 'Cinemachine' started by foxyyhappyw, Apr 26, 2023.

  1. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    Hi, I have a problem with camera blending.
    In the video (starts at 00:19) I showed how camera blending works when I change the camera as follows:
    cam1 > cam2 > cam3 > cam2.
    I noticed that the problem here is when you change the camera from cam2 to cam3 and then back to cam2.
    (The problem also occurs in another sequence, e.g. cam2 > cam3 > cam1 > cam3. It doesn't matter what kind of camera it is, the only problem is the premature change of the camera from e.g. cam1 > cam2 > cam1.)

    Then the camera immediately jumps to its position, bypassing the blending effect.
    I've tried everything but I'm still having this problem and I'm unable to fix it to get rid of this sudden camera jump.
    In my game, generally changing the camera is done by entering the appropriate collider, and that's why this mechanic is important for me.



    I created a script and 3 buttons visible in the video. If it's of any help, here's the script code (I don't use it in my game, it's just for the purpose of presenting the problem to the forum):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class testcam : MonoBehaviour
    7. {
    8.     public CinemachineVirtualCamera cam1;
    9.     public CinemachineVirtualCamera cam2;
    10.     public CinemachineVirtualCamera cam3;
    11.     public CinemachineBrain brain;
    12.  
    13.     public ActiveCamera setCam;
    14.     public enum ActiveCamera { activeCam1, activeCam2, activeCam3 }
    15.  
    16.     private int cam1Priority = 0;
    17.     private int cam2Priority = 0;
    18.     private int cam3Priority = 0;
    19.  
    20.     private void Start()
    21.     {
    22.         cam1Priority = cam1.m_Priority;
    23.         cam2Priority = cam2.m_Priority;
    24.         cam3Priority = cam3.m_Priority;
    25.     }
    26.  
    27.     void Update()
    28.     {
    29.         if (setCam == ActiveCamera.activeCam1)
    30.         {
    31.             cam1Priority = Mathf.Max(cam2Priority, cam3Priority) + 1;
    32.             cam1.m_Priority = cam1Priority;
    33.         }
    34.         if (setCam == ActiveCamera.activeCam2)
    35.         {
    36.             cam2Priority = Mathf.Max(cam1Priority, cam3Priority) + 1;
    37.             cam2.m_Priority = cam2Priority;
    38.         }
    39.         if (setCam == ActiveCamera.activeCam3)
    40.         {
    41.             cam3Priority = Mathf.Max(cam1Priority, cam2Priority) + 1;
    42.             cam3.m_Priority = cam3Priority;
    43.         }
    44.     }
    45.  
    46.     public void buttonCam1()
    47.     {
    48.         setCam = ActiveCamera.activeCam1;
    49.     }
    50.     public void buttonCam2()
    51.     {
    52.         setCam = ActiveCamera.activeCam2;
    53.     }
    54.     public void buttonCam3()
    55.     {
    56.         setCam = ActiveCamera.activeCam3;
    57.     }
    58.  
    59. }
    60.  
     
    Last edited: Apr 28, 2023
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    What version of CM are you using?
     
  3. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    Version 2.8.9

    maybe i should update to the latest version?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Can you try updating to 2.9.5? If package manager doesn't show that version, you can specify it manually like this:

    upload_2023-4-26_12-31-47.png

    upload_2023-4-26_12-32-15.png
     
  5. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
  6. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    any other ideas? (._. )
    I don't know if it's a problem with Cinemachine or if I'm doing something wrong.
     
  7. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    Okay, I figured something out. The "blendDuration" value in the CinemachineBrain.cs script may be the problem.
    By setting "frame.blend.Duration" to a fixed value, not a dynamic one, blending works (probably) correctly.


    In the video, I initially showed what the problem with camera blending is. Then I changed "frame.blend.Duration" to a stable value and it turns out that it helped.

    Unfortunately, it does not solve my problem anyway, because the CinemachineBrain.cs script itself refreshes from time to time and returns to factory settings.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Yeah, that's a hack that I wouldn't recommend. Forcing all blends to be some fixed length will only hide the real problem.
     
    Last edited: Apr 27, 2023
    foxyyhappyw likes this.
  9. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    ya, I know it's not the best solution, but I tried to at least find what could be the problem - and I think I managed to find it.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    I don't think you found the problem, you're just hiding the symptoms.
     
  11. foxyyhappyw

    foxyyhappyw

    Joined:
    Aug 8, 2022
    Posts:
    61
    Okay, I checked almost every version of Cinemachine and found that the problem occurs on version 2.6.17 and below and version 2.7.5 and above.
    It's pretty weird for me, but from version 2.7.1 to 2.7.4 everything works fine.
    Clearly something has been badly implemented since version 2.7.5.



    I tested on the Unity engine version:
    - 2021.3.7f1
    - 2021.3.9f1

    At the moment, until my problem is fixed, I will rather stay with version 2.7.4.