- Home /
Issue Creating Playables, Trying to create Track and clip at runtime
Hello everyone; Need some help with something i'm working on, the idea is that i want to create timeline tracks and clips at Runtime. (in a start function for example)
As it stands i can create a track at runtime but the clip keeps passing me a null reference regardless of how i generate it. Can someone tell me what's going on?
[SerializeField] GameObject m_TestContainer;
[SerializeField] PlayableDirector m_Director;
[SerializeField] PlayableGraph m_Graph;
[SerializeField] TimelineAsset m_Asset;
[SerializeField] TransformTweenTrack m_TweenTrack;
[SerializeField] TransformTweenMixerBehaviour m_TweenMixer;
[SerializeField] TransformTweenClip m_Clip;
[SerializeField] Animator m_Animator;
private void Start()
{
m_Director = m_TestContainer.GetComponent<PlayableDirector>();
m_Animator = m_TestContainer.GetComponent<Animator>();
m_Asset = (TimelineAsset)m_Director.playableAsset;
m_Graph = PlayableGraph.Create("Custom_Graph");
m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
Debug.Log("PlayableGraph - PlayableCount = " + m_Graph.GetPlayableCount());
Debug.Log("PlayableGraph - Outputcount = " + m_Graph.GetOutputCount());
m_Asset.CreateTrack<TransformTweenTrack>(m_TweenTrack, "TransformTweenTrack");
//m_Director.RebuildGraph();
}
Answer by Abraxasalive2 · Jul 26, 2018 at 09:01 PM
Solved the issue,
my "m_track" was null, so the solution was
[SerializeField] PlayableDirector m_Director;
[SerializeField] Animator m_Animator;
[SerializeField] TimelineAsset m_Timeline;
[SerializeField] PlayableGraph m_PlayableGraph;
[SerializeField] Basic_Animation_ControllerTrack m_Track;
[SerializeField] TimelineClip m_Clip;
[SerializeField] GameObject m_Obj;
[SerializeField] ScriptPlayable<Basic_Animation_ControllerMixerBehaviour> m_Mixer;
[SerializeField] double time;
private void Start()
{
m_Director = this.gameObject.GetComponent<PlayableDirector>();
m_Animator = this.gameObject.GetComponent<Animator>();
m_PlayableGraph = PlayableGraph.Create("Custom_Graph");
m_Timeline = (TimelineAsset)m_Director.playableAsset;
m_PlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
PropertyName name = nameof(m_Obj);
m_Track = m_Timeline.CreateTrack<Basic_Animation_ControllerTrack>(m_Track, "Custom_AnimationTrack");
m_Mixer = (ScriptPlayable<Basic_Animation_ControllerMixerBehaviour>)m_Track.CreateTrackMixer(m_PlayableGraph, m_Obj, 0);
m_Clip = m_Track.CreateClip<Basic_Animation_ControllerClip>();
m_Timeline.CreatePlayable(m_PlayableGraph, m_Obj);
m_Clip.duration = 1;
Basic_Animation_ControllerClip Clip = (Basic_Animation_ControllerClip)m_Clip.asset;
Once i had that now it's just solving how to assign Exposed References at runtime
Your answer
![](https://koobas.hobune.stream/wayback/20220612171618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 5.5 Playing inside an animation forward and backwards. 0 Answers
how do you get the PlayableDirector component in unity c# 1 Answer
timeline not play in mobile 0 Answers
How do you get curve values on an animation clip playing from a timeline? 0 Answers
Why does the Animation Track control the track bindings position, 1 Answer