Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting up/Configuring Cinemachine at runtime?

Discussion in 'Cinemachine' started by jwvanderbeck, Jul 13, 2017.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Really REALLY like what I have been seeing with Cinemachine, and while I haven't yet jumped into it, I definitely plan to. It will be absolutely perfect for a part of my game if I can get it to do what I need.

    How much of Cinemachine can be manipulated at runtime? A large part of my game is actually designed for content creators, and so I have a planned system in my game that lets players set up camera shots on a rudementary timeline. Nothing as in depth as a NLE, or even as in depth as what Unity provides, but something along the lines of "At time X cut to Camera Y". I thought I would be writing a lot of this camera system myself, but now I am eyeing Cinemachine to do it.

    So how robust is the runtime API for this? Can the timeline sequences I have seen in the demos be setup programmatically at runtime? Can I allow a player to essentially setup a camera with framing and some settings and then drop that into the Cinemachine timeline?
     
  2. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    Yes to all of the above. Gregory has completely opened it up so you can customise and extend it however you wish.

    A really powerful way of working is to trigger Timeline sequences from code/game events/whatever and put your camera switching/blending timing in there (and anything else!)

    Otherwise, simply turning Cinemachine cameras on/off based on whatever events will trigger cameras and they will blend/cut based on their Priority and the Default or Custom Blends.

    We've spent a long time designing these features as it can be very powerful and versatile. You can easily setup a state machine arrangement - code turning cameras on and off - and they're all managed appropriately due to the priority and custom blending.
    upload_2017-7-13_16-56-35.png

    For example, on a game I worked on years ago, we had 20+ Free Look rigs just for the character's localmotion system. They were triggered by animations and game events, a big controlled sea of cameras blending between each other.

    Character jumps - blend to a slightly different rig which lets the character go higher on the screen
    Enemies approach - blend to a further back rig
    Run through tunnel - blend to a close-in rig
    Injured - get closer and put some handheld noise on the cameras
    You get the idea - 20+ cameras all blending around to best suit what's happening

    Cameras can really compliment and reinforce gameplay. We're trying to make it as easy as possible for you to build sophisticated camera systems to support whatever you've got going on.
     
    allyn_alves, Matisseio, Foge and 3 others like this.
  3. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    In Unity the states are closely tied to animations aren't they? We probably won't be using those as our states are mostly not tied to animation.
     
  4. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    The above things weren't only states, they're really just concepts. The priority/blend tools allow you to craft the camera behavior by just activating cameras through code or anything else.
     
  5. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Sorry for the late reply, but I have a related follow-up if you don't mind: for my use case I'm calling camera commands from an external scripting language, and most of the utility I need comes in the form of "Transition to camera <X> with <Y> blend style over s seconds". I already have a complete cutscene system written and tested, so refactoring everything to work with timelines and inspector-configured blend lists isn't practical. Am I correct that the intended way to do this in code would be to cache a reference to my CinemachineBrain, create a custom CinemachineBlendDefinition for every combination of cut and curve/timing I want, then do something like the following?

    Code (csharp):
    1.  
    2.         CinemachineBlendDefinition someCustomBlend;
    3.         CinemachineVirtualCamera currentCamera;
    4.         CinemachineVirtualCamera newCamera;
    5.         CinemachineBrain myBrain;
    6.  
    7.         myBrain.m_DefaultBlend = someCustomBlend;
    8.         newCamera.gameObject.SetActive(true);
    9.         currentCamera.gameObject.SetActive(false);
    10.  
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
  7. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Awesome, thank you very much for the quick reply :)
     
  8. Kokowolo

    Kokowolo

    Joined:
    Mar 26, 2020
    Posts:
    51
  9. conceptfac

    conceptfac

    Joined:
    Feb 15, 2018
    Posts:
    23
    But how to know when the blend transition is finished?
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,623
    @conceptfac You can check CinemachineBrain.IsBlending