Search Unity

Question A way or a tool to check if and where a gameobject is being called in timelines / animations.

Discussion in 'Timeline' started by nicolasc_unity974, Nov 28, 2022.

  1. nicolasc_unity974

    nicolasc_unity974

    Joined:
    Sep 21, 2022
    Posts:
    7
    Hello, I was wondering if someone knows a way to check in the hierarchy of a scene if a specific gameobject is being controlled/assigned in any timelines or animators in the project.
     
    Last edited: Dec 6, 2022
  2. superarhow

    superarhow

    Joined:
    Mar 24, 2015
    Posts:
    5
    Hello,
    Timeline has two type of bindings: generic binding and reference bindings, and they are all saved in scene.
    So if you check all timeline's binding table, you can get the objects they attached.
    Code (CSharp):
    1.     public static void SearchAllBindings()
    2.     {
    3.         foreach (var scenePath in AssetDatabase.FindAssets("t:scene").Select(AssetDatabase.GUIDToAssetPath))
    4.         {
    5.             var scene = EditorSceneManager.OpenScene(scenePath);
    6.             Debug.Log($"Processing scene:{scenePath}");
    7.             foreach (var director in scene.GetRootGameObjects().SelectMany(x => x.GetComponentsInChildren<PlayableDirector>()))
    8.             {
    9.                 var so = new SerializedObject(director);
    10.                 so.forceChildVisibility = true;
    11.                 var sceneBinding = so.FindProperty("m_SceneBindings");
    12.                 for (int i = 0; i < sceneBinding.arraySize; i++)
    13.                 {
    14.                     var property = sceneBinding.GetArrayElementAtIndex(i);
    15.                     var keyProp = property.FindPropertyRelative("key");
    16.                     var valueProp = property.FindPropertyRelative("value");
    17.                     var resolvedValue = director.GetGenericBinding(keyProp.objectReferenceValue);
    18.                     if (resolvedValue != null)
    19.                     {
    20.                         Debug.Log($"  object:{resolvedValue} is binding to:{director}", resolvedValue);
    21.                     }
    22.                 }
    23.                 var refBinding = so.FindProperty("m_ExposedReferences").FindPropertyRelative("m_References");
    24.                 for (int i = 0; i < refBinding.arraySize; i++)
    25.                 {
    26.                     var property = refBinding.GetArrayElementAtIndex(i);
    27.                     var firstProp = property.FindPropertyRelative("first");
    28.                     var valueProp = property.FindPropertyRelative("second");
    29.                     var value = (director as IExposedPropertyTable).GetReferenceValue(new PropertyName(firstProp.stringValue), out var isValid);
    30.                     Debug.Log($"  object:{valueProp.objectReferenceValue},{value} is binding to:{director}", valueProp.objectReferenceValue);
    31.                 }
    32.             }
    33.         }
    34.     }
    Good luck.