Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    16
    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:
    74
    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
  3. HugMat

    HugMat

    Joined:
    Mar 30, 2017
    Posts:
    16
    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:
    74
    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:
    16
    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:
    Jul 21, 2017
    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:
    Jul 21, 2017
    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:
    16
    Hello leoleroy,

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

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    71
  10. 1257961942

    1257961942

    Joined:
    Jul 22, 2017
    Posts:
    3
    Is there a API in unityengeion to get a guid?