Search Unity

Giving a Cinemachine Camera priority over a Cinemachine Track on a timeline

Discussion in 'Cinemachine' started by Aaron-Meyers, Nov 21, 2018.

  1. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    I've got a sequence of cameras playing back on a Cinemachine Track on a timeline, but I'd like to be able to be able to enable another Camera that will effectively take over from the Cinemachine Track on the timeline.

    I gave this camera a higher priority than all the cameras being used on the track, but it doesn't seem to make a difference. Any suggestions for how to get this going?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Timeline overrides priority, so that approach won't work. The way to get what you're looking for is to enable another timeline with a CM track on it that holds your camera.
     
  3. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Thanks! This *does* work, but its a little bit hacky :p

    The logic for which camera takes precedence is a bit murky. If both timelines are playing, regardless of camera priority level, it seems like the last director to start playing gets it. I think it would make more sense if with multiple timelines playing back, it deferred to the camera with the highest priority level. Also, would be nice to be able to have a smooth transition instead of always a hard cut using this method.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Correct, the most recently-activated one wins.
    You can get a smooth transition by putting an easeIn/easeOut setting on the CM clip that punches in. That will make it blend in/out with whatever vcam it's overriding
     
  5. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    I'm not finding that to be the case. For me its always a hard cut.
     
  6. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    The CinemachineBrain has a default 2 second ease in out set and I also have a custom blend set going to this camera that I want to override the timeline.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    When you use Timeline, the timeline clip itself controls the blending, and completely overrides any blend setting on the brain. The default blend and custom blend settings are irrelevant in this context.

    Click on the CM clip in the timeline:

    upload_2018-11-26_14-35-43.png

    and look at the inspector. Notice these fields:

    upload_2018-11-26_14-36-50.png

    When you set them, your clip will look something like this:

    upload_2018-11-26_14-37-36.png

    Effectively, you are blending the clip in and out with whatever would be there in its absence.
     
  8. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    yea not really a good solution for me because i only want the transition when i flip the camera on or off... not for a fixed time dictated by where the ins and outs are on the timeline clip.

    i also have a separate system that performs some stuff based on the position of the virtual camera's LookAt target's world space position and it appears that sometimes when doing these multi-timeline transitions, behind the scenes, Cinemachine is creating a virtual camera called "Mid-blend" that doesn't have a LookAt target so I'm getting null reference exceptions from that.

    *shrug* thanks for your help, but it seems like i'm trying to do something too far from Cinemachine's built-in functionality.

    I think it'd be nice if there was an option for camera priority to always be respected irregardless of whether something is playing on a timeline or not.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Don't give up so quickly, there may be ways around the issues you're having.

    Let's talk a little about this override camera.

    If you always place the clip at the start of timeline, then it will blend in according to the blend time you set, as soon as the override timeline is enabled. So far so good. The problem is that you don't know how long the timeline should remain enabled, so you can't give the clip a definite length, right?

    Question: is there an upper limit on how long the override camera will be enabled?

    If so, then you can make the clip that length, followed by an ease-out of fixed time. When you want to disable the override cam, just seek to the point in the override timeline at which the fade-out begins.

    If there is no upper limit on the override time, then you can make a little script that loops the timeline (using seek) between the fades, until the override is stopped, at which point you seek to the fade out and let the timeline finish.

    For the "mid-blend" thing, yes, that is a thing that gets created when you interrupt a blend-in-progress with another blend. That becomes the outgoing "vcam". However, the incoming vcam is always the most-recently-activated vcam, and should have a valid LookAt target if you set one. Brain.ActiveVirtualCamera will always return the incoming vcam, if a blend is in progress. Could you not use that?
     
    Last edited: Nov 26, 2018
  10. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Yeah... unfortunately, a further wrinkle, is that I need the ability to pause the main timeline that has the main cinemachine camera track when I jump to the overriding camera and it appears that those transitions don't work once you've paused the original timeline :(
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Don't pause it, set its timescale to 0
     
    Last edited: Nov 26, 2018
  12. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Cool... well, it's mostly working now... I'm noticing that I'm getting a few frames of null ref exceptions due to that previously mentioned issue with the mid-blend cam... it's actually populating the CinemachineBrain.ActiveVirtualCamera property so your fix for that didn't quite work, but I think I can live with it in this particular case... after the main timeline loops around a couple times, it doesn't appear to happen and I didn't notice it producing any visual pops.

    Thanks for helping me find a solution!
     
  13. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Ooops in my haste I actually misunderstood something in my console log. The mid-blend cam is not the active virtual camera, in this case it is ActiveBlend.CamB, but I'm guessing there isn't an easy solution there since it's trying to blend back to a blend on the main timeline.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Hmmm... even if it's blending to a blend in the main timeline, you should be able to get the real vcam that's ultimately the incoming vcam. What version of CM are you using?

    Is it possible that not all the vcams in your main timeline have LookAt targets? If that's the case you just need a null check in your logic, and perhaps a memory of the most recent non-null LookAt target.
     
  15. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Hmmm its the latest version from the package manager (2.2.7).

    All my cameras have LookAt targets... I just added a null check that takes CamA's LookAt target if CamB's is null.