Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question How to get rid of "unused bindings"?

Discussion in 'Timeline' started by Peter77, May 23, 2023.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,650
    I'm using Unity 2022.2.18 and Timeline 1.7.4.

    How can I delete the stuff listed under "Unused Bindings" in the Playable Director Component?

    I don't need a perfect solution, just the quickest and dirtiest method that will do the trick.
     
  2. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    140
    There should be a [-] button below the binding list. you can delete unused bindings by clicking it.
     
    Peter77 likes this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,650
    Thanks, that definitely works. But I have like thousands of unused bindings and the Inspector is super unresponsive. It takes forever to delete just one. Is there any way to get rid of all of them in one go?
     
  4. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    140
    You can use this script to remove them. Just put this script in your project, open scene and attach the script to any arbitrary GameObject, put all PlayableDirectors you want to clear unused bindings into Directors, and hit [Remove Unused Bindings]. You can then remove this script from your project.
    (I have no warranty to the script)

    remove_unused_bindings.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using UnityEditor;
    5. using UnityEngine;
    6. using UnityEngine.Playables;
    7.  
    8. public class RemoveUnusedBindings : MonoBehaviour
    9. {
    10.     [SerializeField] private PlayableDirector[] directors;
    11.  
    12.  
    13. #if UNITY_EDITOR
    14.  
    15.     [CustomEditor(typeof(RemoveUnusedBindings))]
    16.     public class RemoveUnusedBindingsEditor : Editor
    17.     {
    18.         public override void OnInspectorGUI()
    19.         {
    20.             base.OnInspectorGUI();
    21.             if (GUILayout.Button("Remove Unused Bindings")) {
    22.                 RemoveUnusedBindings();
    23.             }
    24.         }
    25.  
    26.         private void RemoveUnusedBindings()
    27.         {
    28.             var directors = (target as RemoveUnusedBindings).directors;
    29.             if (directors == null) return;
    30.  
    31.             foreach (var director in directors)
    32.             {
    33.                 if (!director) continue;
    34.  
    35.                 var directorSO = new SerializedObject(director);
    36.                 var sceneBindings = directorSO.FindProperty("m_SceneBindings");
    37.                 var assetBindings = director.playableAsset.outputs.ToArray();
    38.  
    39.                 for (var i = sceneBindings.arraySize - 1; i >= 0; i--) {
    40.                     var key = sceneBindings.GetArrayElementAtIndex(i).FindPropertyRelative("key").objectReferenceValue;
    41.                     bool isUnused = assetBindings.All(binding => binding.sourceObject != key);
    42.                     if (isUnused) {
    43.                         sceneBindings.DeleteArrayElementAtIndex(i);
    44.                     }
    45.                 }
    46.  
    47.                 directorSO.ApplyModifiedProperties();
    48.             }
    49.         }
    50.     }
    51.  
    52. #endif
    53. }
    54.  
    ... or, just reset your PlayableDirector Component, and reattach those bindings which are in use.
    (if there is little PlayableDirector to work)