1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Timeline + Cinemachine : create Shots by script

Discussion in 'Timeline' started by HugMat, Jul 10, 2017.

  1. HugMat

    HugMat

    Joined:
    Mar 30, 2017
    Posts:
    14
    Hi,
    I'm using Timeline and Cinemachine and I want to create new CinemachineShots in a CinemachineTrack via scripting, but I have 2 issues :
    - I don't know how to add a CinemachineShot in the track via script : the only way I found to do so is creating a default clip in the Cinemachine Track, but then I can only access it as a TimelineClip
    - When I have my Cinemachine Shot, I want to set its VirtualCamera but since it is an ExposedReference I don't know how. I guess i have to use the CreatePlayable method but I don't know how

    Thanks a lot
     
  2. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    47
    In order to get access to CinemachineShot, you will need to do:
    Code (CSharp):
    1. var cinemachineShot = myTimelineClip.asset as CinemachineShot;
    Here's why: Timeline is built on the Playable system to play animation, audio and custom scripts, which means that each TimelineClip contains a reference to a PlayableAsset, which contains the data need by the playable to operate at runtime. A TimelineClip is generic and is only concerned with timing (duration, start, end, etc.) and blending. If you want to get access to data specific only to a certain type of clip (like the Virtual Camera property of a CinemachineShot), you will need to through the TimelineClip's asset.

    To set the Virtual Camera:
    Code (CSharp):
    1. myCinemachineShot.VirtualCamera.exposedName = UnityEditor.GUID.Generate().ToString();
    2. myPlayableDirector.SetReferenceValue(myCinemachineShot.VirtualCamera.exposedName, myVirtualCamera);
    Here's why: Since CinemachineShot is an asset, it cannot contain any reference to an object in a scene. So you need to ask the PlayableDirector to remember that VirtualCamera (an exposed reference) refers a given object in the scene. You don't have to do it inside the CreatePlayable method.

    Hope this helps!

    [EDIT] I forgot to initialize the exposed reference name.
     
    Last edited: Jul 19, 2017 at 10:37 PM
  3. HugMat

    HugMat

    Joined:
    Mar 30, 2017
    Posts:
    14
    Yeah, it helps a lot !
    I'm having another issue though : when I add a second CinemaShot on my track, and I want to set its VirtualCamera, it modifies also the VirtualCamera for the first Shot.
    I've tried to change the exposedname of the second shot but the problem remains...
     
  4. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    47
    I forgot one important step :confused:

    Code (CSharp):
    1. myCinemachineShot.VirtualCamera.exposedName = UnityEditor.GUID.Generate().ToString();
    It's not obvious that you need to initialize exposedName. Sorry about that.;)
     
  5. HugMat

    HugMat

    Joined:
    Mar 30, 2017
    Posts:
    14
    It works, thanks a lot.
    I just have one last question : is it possible to "update" the CinemachineTrack in Run mode.
    Indeed, the camera linked to my CinemachineTrack does not use the CinemachineShots I create in Run, like it doesn't detect them
     
  6. leoleoroy

    leoleoroy

    Joined:
    Friday
    Posts:
    2
    Hello HugMat

    Could you tell me how to creating a default clip in the Cinemachine Track, but then I can only access it as a TimelineClip?
    I try a lot of time, still don't how to access.
    Thank you~
     
  7. leoleoroy

    leoleoroy

    Joined:
    Friday
    Posts:
    2
    Hello julienb:)

    I try to use your method.
    But "var cinemachineShot = myTimelineClip.asset as CinemachineShot;"
    I just have "CinemachineClearShot" can be choose >_<
     
  8. HugMat

    HugMat

    Joined:
    Mar 30, 2017
    Posts:
    14
    Hello leoleroy,

    are you using Cinemachine.Timeline ? You have to to chose CinemachineShot