Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Altering look at and follow in CinemachineShot via timeline

Discussion in 'Cinemachine' started by mradfo21, Jun 10, 2018.

  1. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    181
    hey so i can't quite figure out the best way to do this.. I'm trying to set a cinemachine shot's follow and look at at run-time

    Code (CSharp):
    1.  
    2. foreach (var playableAssetOutput in director.playableAsset.outputs)
    3. {
    4.  
    5.  if (playableAssetOutput.streamName == "Cinemachine Track"){
    6.  
    7.   director.SetGenericBinding(playableAssetOutput.sourceObject,cmBrain);
    8.   var cinemachineTrack = playableAssetOutput.sourceObject as CinemachineTrack;
    9.     foreach( var clip in cinemachineTrack.GetClips() ){
    10.           var cinemachineShot = clip.asset as CinemachineShot;
    11.           director.SetReferenceValue(cinemachineShot.VirtualCamera.m_LookAt , dynamicLookAt.transform);
    12.    }
    13.  
    14.  }
    15.  
    16.                 }

    so you can see hre i try and set the VirtualCamera's m_LookAt ... but unity complains

    upload_2018-6-10_1-15-50.png


    Can I somehow cast it to a Cinemachine Virtual Camera to set this value?


    Before the package manager I could easily look through the cinemachineVirtualCameraBase code.. i kinda miss that..
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Try using the vcam.LookAt accessor instead of vcam.m_LookAt
     
  3. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    181
    sadly I get this error:
    Assets/Code/General/TimelineBindings.cs(75,74): error CS1061: Type `UnityEngine.ExposedReference<Cinemachine.CinemachineVirtualCameraBase>' does not contain a definition for `LookAt' and no extension method `LookAt' of type `UnityEngine.ExposedReference<Cinemachine.CinemachineVirtualCameraBase>' could be found. Are you missing an assembly reference?



    BUT here's how i solved this for anyone else running into this problem. Before I execute any of the code I just find all the vcams in the heirarchy (I assume your instantiating a timeline like me and filling in the bindings etc at runtime)

    Code (CSharp):
    1.  
    2.             List<CinemachineVirtualCamera> vcams = new List<CinemachineVirtualCamera>();
    3.             foreach(CinemachineVirtualCamera vcam in GetComponentsInChildren(typeof(CinemachineVirtualCamera))){
    4.                 vcams.Add(vcam);
    5.             }
    6.             for (int i =0; i < vcams.Count; i++){
    7.                 if (remapLookAt == true){
    8.                     vcams[i].m_LookAt = dynamicLookAt.transform;
    9.                 }
    10.                 if (remapFollow == true){
    11.                     vcams[i].m_Follow = dynamicFollow.transform;
    12.                 }
    13.  
    14.             }
    Nothing elegant.. just find them all and set this stuff. What I think i'm going to do is put a component on each of the vcams that specifies if per shot it wants the lookat and the follow by the dynamic binding.


    Can I suggest however that the cinemachine shot make the Follow and LookAt exposed references that just show up as part of the binding? That could really simplify this and preserve the power of cinemachine's look at and follow options!