- Home /
How can i code to delete unused bindings in PlayableDirector?
Becasuse of some manual copies of PlayableDirector,now PlayableDirector Components in some Prefab have many unused bindings. Are there some apis to get all bindinds in PlayableDirector?
Answer by mrstruijk · Apr 06 at 12:39 PM
This may have changed in later versions I think. In Unity 2021.2.16 / Timeline 1.6.4 at least there's a little minus sign at the very bottom-right of the Bindings field. Highlight the unused binding (or entire unused Timeline), and hit the minus to remove the ones not used.
Answer by Wenyi751 · May 20, 2021 at 10:00 AM
It's hard to delete the unused bindings...since it stored in a property named 'm_SceneBindings' which cannot be read/written directly. A workaround to remove the unused bindings is to create a new Playable Director and copy the bindings from the old one.
Sample code:
private static void PlayableDirectorRebinding(PlayableDirector playableDirector)
{
if (playableDirector != null)
{
var timeline = playableDirector.playableAsset as TimelineAsset;
if (timeline != null)
{
var bindings = new Dictionary<Object, Object>();
foreach (var playableBinding in timeline.outputs)
{
bindings.Add(playableBinding.sourceObject, playableDirector.GetGenericBinding(playableBinding.sourceObject));
}
var timelineGameObject = playableDirector.gameObject;
GameObject.DestroyImmediate(playableDirector);
playableDirector = timelineGameObject.AddComponent<PlayableDirector>();
foreach (var entry in bindings)
{
playableDirector.SetGenericBinding(entry.Key, entry.Value);
}
}
}
}
Reference form here: https://blog.csdn.net/cai612781/article/details/99947344
Your answer
Follow this Question
Related Questions
Stop/start Animation Timeline on click? 0 Answers
TIMELINE: How to set a character’s initial position, without overriding the animation transforms? 2 Answers
Customize Timeline Clip background 0 Answers
Timeline reverse all clips in 0 Answers
How can I slow down to stop(HumanoidIdle) character when getting close to a object using timeline ? 0 Answers