Hi. I’m trying to make component which has multiple timeline and play one of that by scripting in runtime.
But it seems that PlayableDirector.Play(PlayableAsset) makes tons of GC. Here is my test code:
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[RequireComponent(typeof(PlayableDirector))]
public class TimelineTest : MonoBehaviour
{
public TimelineAsset[] TimelineAssets;
public float Step = 1.0f;
private PlayableDirector director;
private float elapsedTime;
private int index;
private void Start()
{
this.director = this.GetComponent<PlayableDirector>();
this.director.Play(this.TimelineAssets[0]);
}
private void Update()
{
this.elapsedTime += Time.deltaTime;
if (this.elapsedTime >= this.Step)
{
this.index++;
if (this.index >= this.TimelineAssets.Length)
{
this.index = 0;
}
this.director.Play(this.TimelineAssets[this.index]);
this.elapsedTime = 0;
Debug.Log($"Timeline is changed : {this.index}");
}
}
}
Methods which generate GC are here:
Is there any way for selecting/playing Timeline effectively, especially without GC? My goal is that make responseive object that playing timeline for its state.
Thanks.