Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Scenes binding not being cleared

Discussion in 'Timeline' started by R40ul_OSG, Jul 5, 2018.

  1. R40ul_OSG


    Sep 2, 2016
    I was profiling my project today, and noticed that a number of large images I only use in cinematics were loaded on game start even though that cinematic is played much later in the game. I started investigating, and used the "Asset/Find References in scene" function on the Timeline that uses those images. I discovered that it was being referenced by the PlayableDirector in the main scene of my game although the field "Timeline Asset" was null.
    Switching to debug mode, I realized that PlayableDirector has 661 "scene bindings" and a good number of "Exposed references".
    Shouldn't these things be cleared when the Timeline Asset is set to null? I tried to look in the code to find a way to do that cleaning myself but could find anything...
    (An important thing to note is that I rebind my tracks manually as I am using Timeline in a multiscene context)

    Can anyone help with that? (I'm on Unity 2017.2)
  2. julienb


    Unity Technologies

    Sep 9, 2016
    You found a bug. When a track with a binding is deleted, the bound object is not correctly deleted from the playable director. I'll open a new issue for that.

    In your case, looks like there are images that were bound to tracks that were deleted. As a workaround, you have two choices. You can delete and recreate the playable director, but you'll have to rebind all your tracks. If you want to avoid that, then you can run the following script which will purge the unbound objects:

    Code (CSharp):
    1. [MenuItem("GameObject/Purge Director Bindings")]
    2. public static void PurgeBindingsForAllDirectors()
    3. {
    4.    var directors = Object.FindObjectsOfType<PlayableDirector>();
    5.    foreach (var director in directors)
    6.    {
    7.       var dirSO = new SerializedObject(director);
    8.       var sceneBindings = dirSO.FindProperty("m_SceneBindings");
    9.       for (var i = sceneBindings.arraySize - 1; i >= 0; i--)
    10.       {
    11.          var binding = sceneBindings.GetArrayElementAtIndex(i);
    12.          var key = binding.FindPropertyRelative("key");
    13.          if (key.objectReferenceValue == null)
    14.             sceneBindings.DeleteArrayElementAtIndex(i);
    15.       }
    17.       dirSO.ApplyModifiedProperties();
    18.    }
    19. }
    Mnemonic426 and senkal_ like this.
  3. R40ul_OSG


    Sep 2, 2016
    Thanks for the answer.
    I already chose the first solution (which is to delete the Playable Director at the end of each cinematic), and it works much better now.
    Good to hear that you filed a bug report!
    julienb likes this.
  4. unity_KI4_DqSao3pPzw


    Oct 4, 2018
    @julienb This also happens with the exposed references. Is it already fixed? What is the workaround?