Search Unity

Using API to blend CM Camera's outside of timeline

Discussion in 'Cinemachine' started by lagerdalek, Nov 19, 2017.

  1. lagerdalek

    lagerdalek

    Joined:
    Jun 27, 2016
    Posts:
    3
    I'm trying (quite poorly) to programatically blend 2 Cinemachine cameras rather than use the timeline.

    After struggling with the old 1.1 docs online (d'oh) I found the API documentation in the package, however still not to sure how to implement.

    I have created a new CinemachineBlend object, with a fairly rudimemtary AnimationCurve (
    Code (csharp):
    1. new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1))
    ), however not to sure how to proceed from here, if, indeed, this is the correct first step.

    The ActiveBlend object on the CinemachineBrain is just an accessor (externally read only), and I've tried calling
    Code (csharp):
    1. UpdateCameraState()
    in both the Update and a Coroutine. There is a potentially useful method on CinemachineBrain
    Code (csharp):
    1. SetCameraOverride
    but it's very firmly labelled 'Do Not Use'.

    I considered setting up a Timeline and programatically swapping out cameras on that, but that felt, both, less flexible a solution and a bit of a hack.

    At this point, I have to admit, I've got no idea what I'm doing.

    Any tips or links would be greatly appreciated.
     
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Have you tried to just change priority of your vCams?
     
  3. lagerdalek

    lagerdalek

    Joined:
    Jun 27, 2016
    Posts:
    3
    It's not just switching cameras I want, I want to select 2 cameras and blend between them, like I can on the timeline.

    Also, the nature of the game means that I cannot be sure of which cameras need to be blended until runtime, and I may even programatically generate cameras
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    @lagerdalek Take a look at CinemachineMixingCamera. It's designed to allow you to maintain a programmatically-controlled blend between multiple vcams. Add the vcams as transform children to the mixing camera, and manipulate their weights from your script. When the MixingCamera is active, it will look to the system like a single vcam, and will blend to and from other vcams normally, but its own output is the result of the blend of its children.
     
    dadude123 likes this.
  5. lagerdalek

    lagerdalek

    Joined:
    Jun 27, 2016
    Posts:
    3
    Thanks a lot - I'll give that a try