When I dynamically create cinemachinShot to timelineasset, processFrame() func in CinemachineMixer can’t get process weight value,but 0 or 1 value.
After in editor hierarchy clicked playabledirector and showed the timeline window, then normal linear values can be obtained.
using Cinemachine;
using Cinemachine.Timeline;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public class DynamShotDemo : MonoBehaviour
{
public CinemachineBrain cinemachineBrain;
public PlayableDirector playableDirector;
public Transform _vcamsParent;
private CinemachineTrack cinemachineTrack;
private TimelineAsset timelineAsset;
void Start()
{
timelineAsset = playableDirector.playableAsset as TimelineAsset;
var tracks = timelineAsset.GetOutputTracks();
foreach (TrackAsset track in tracks)
if (track.name == "Cinemachine Track")
{
cinemachineTrack = track as CinemachineTrack;
break;
}
// clear clips
var clips = cinemachineTrack.GetClips().ToArray();
foreach (var c in clips)
cinemachineTrack.DeleteClip(c);
// clear vcams
var count = _vcamsParent.childCount;
for (var d = count - 1; d >= 0; d--)
DestroyImmediate(_vcamsParent.GetChild(d).gameObject);
// create vcam and shot clips
AddNode(0, new Vector3(0, 0, 0), 0, 1f);
AddNode(1, new Vector3(5, 0, 5f), 0, 2f);
AddNode(2, new Vector3(-5, 0, 5f), 1, 4f);
playableDirector.RebuildGraph();
}
private void AddNode(int idx, Vector3 position, float start, float duration)
{
var node = new GameObject("VCam-" + idx);
node.transform.SetParent(_vcamsParent);
node.transform.position = position;
var vcam = node.AddComponent<CinemachineVirtualCamera>();
TimelineClip clip = cinemachineTrack.CreateClip<CinemachineShot>();
clip.start = start;
clip.duration = duration;
var shot = clip.asset as CinemachineShot;
shot.VirtualCamera.exposedName = node.name;
playableDirector.SetReferenceValue(shot.VirtualCamera.exposedName, vcam);
}
}
Not active playableDirector in hierachy:

Afte active playableDirector in hierachy:

I debug CinemachineMixer class, and found that in the processframe func, before active playableDirector in hierarchy, weight can only get the value of 0 or 1. Don’t know why this is happening:

