Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Blend won't stop and it's causing lots of problems

Discussion in 'Cinemachine' started by gdp2, Mar 7, 2018.

  1. gdp2

    gdp2

    Joined:
    Dec 6, 2016
    Posts:
    28
    Hi,

    So I've got two virtual cameras that I want to blend between. I want to zoom in with my second camera after blending and then I want to zoom out again after a certain condition is met. Actually, I've already somewhat described my problem here.

    I have already achieved a blend between the two cameras with the following code:

    Code (CSharp):
    1. firstVCam.enabled  = false;
    2. secondVCam.enabled = true;
    And I am attempting to zoom in with the second camera after the blend starts with this code:

    Code (CSharp):
    1. secondVCam.m_Lens.FieldOfView = 20; // zooming out is obviously just setting this value higher again
    But there are some problems. First off, the zooming in with the secondVCam does not have any visual effect unless I pause my game, which happens with this code:

    Code (CSharp):
    1. void PauseGame() {
    2.   isRunning = false;
    3.   Canvas ().pausePanel.SetActive (true);
    4.   Time.timeScale = 0;
    5.   Cursor.visible = true;
    6.   Cursor.lockState = CursorLockMode.Confined;
    7. }
    However, the zooming in does have an immediate visual effect if I instead set the FOV on the firstVCam. But I cannot do this because the actual camera's physics start to get wonky if I do this stuff on the firstVCam. I believe that the root cause of this problem is that the firstVCam remains in a "Live" status even after it's not enabled. The reason for this seems to be that the vcams do not stop blending. I determined this by putting the following code in my Update() method:

    Code (CSharp):
    1. Debug.LogError("IsBlending: " + Camera.main.GetComponent<CinemachineBrain>().IsBlending);
    Which continuously outputs IsBlending: True in the console. It seems that the cameras do not stop blending, which explains why the firstVCam refuses to stop being "Live". According to CinemachineBrain.IsLive()'s summary:

    So I think I need to somehow forcibly tell my vcams to stop blending at a certain point. How do I do that? Also, am I correct in my assumptions as to the underlying causes of these issues? I would certainly appreciate any feedback to help me get a better understanding. Perhaps @Adam_Myhill can provide some insight?
     
  2. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Quick question up front:

    Why not just enable camera 2 and have camera 2 have a more telephoto lens? This way you get the blend and the zoom at the same time? It also means you can adjust more than the zoom for camera 2 if desired (composition, position - whatever)

    It seems like all the other issues are due to they way you're trying to do zooming, which is so much easier if you just blend to a camera with a different lens. Would that not work?
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,558
    Yes. What Adam said.
    Also: the blend is never going away because you've paused the game. By default, the cameras pause too, along with any blends. If you don't want them to, then you can check the "Ignore Timescale" checkbox on the Brain.
     
  4. gdp2

    gdp2

    Joined:
    Dec 6, 2016
    Posts:
    28

    Thank you both for your advice. Your advice, @Adam_Myhill, has helped to simplify my code a lot and it seems to work. Your advice, @Gregoryl, about the "Ignore Time Scale" checkbox is exactly what I needed with all the issues I described. Thanks again, I really appreciate it.