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
foreach (var playableAssetOutput in director.playableAsset.outputs)
{
if (playableAssetOutput.streamName == "Cinemachine Track"){
director.SetGenericBinding(playableAssetOutput.sourceObject,cmBrain);
var cinemachineTrack = playableAssetOutput.sourceObject as CinemachineTrack;
foreach( var clip in cinemachineTrack.GetClips() ){
var cinemachineShot = clip.asset as CinemachineShot;
director.SetReferenceValue(cinemachineShot.VirtualCamera.m_LookAt , dynamicLookAt.transform);
}
}
}
so you can see hre i try and set the VirtualCamera’s m_LookAt … but unity complains
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…
Try using the vcam.LookAt accessor instead of vcam.m_LookAt
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)
List<CinemachineVirtualCamera> vcams = new List<CinemachineVirtualCamera>();
foreach(CinemachineVirtualCamera vcam in GetComponentsInChildren(typeof(CinemachineVirtualCamera))){
vcams.Add(vcam);
}
for (int i =0; i < vcams.Count; i++){
if (remapLookAt == true){
vcams[i].m_LookAt = dynamicLookAt.transform;
}
if (remapFollow == true){
vcams[i].m_Follow = dynamicFollow.transform;
}
}
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!