Search Unity

Scenes binding not being cleared

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

  1. Antoine_OSG

    Antoine_OSG

    Joined:
    Sep 2, 2016
    Posts:
    43
    Hello,
    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

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    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.       }
    16.  
    17.       dirSO.ApplyModifiedProperties();
    18.    }
    19. }
     
    Mnemonic426 and senkal_ like this.
  3. Antoine_OSG

    Antoine_OSG

    Joined:
    Sep 2, 2016
    Posts:
    43
    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

    unity_KI4_DqSao3pPzw

    Joined:
    Oct 4, 2018
    Posts:
    1
    @julienb This also happens with the exposed references. Is it already fixed? What is the workaround?
     
    NestorAlgieri likes this.
  5. rookiemike

    rookiemike

    Joined:
    Jul 10, 2017
    Posts:
    4
    Same problem with exposed references.
    Unity Version: 2019.4.10f1
    Timeline Version: 1.2.17
     
  6. Keepabee

    Keepabee

    Joined:
    Jul 12, 2012
    Posts:
    58
    Exposed references are never removed when removing PlayableAsset/Timeline reference from a PlayableDirector.
    Exposed references still remain even if you purge all m_SceneBindings.

    Unity version 2021.3.26f1
    Timeline version: 1.6.5
    ... but I'm willing to guess this is true for all versions up to latest 2023 alpha, too, just haven't had the time to test this yet, because...

    ... is anyone at Unity aware of the kinds of messes PlayableDirectors/Timelines can create when Scene Bindings and Exposed Properties linger like this if some artist has at any point duplicated some PlayableDirector or Prefab including one as basis for another Prefab, and you later on try to build Addressable bundles? Suddenly every Scene is now tracking dependencies to everywhere, and someone smart spends a lot of time making a dependency tracking system that splits all Addressables into separate Groups per "game level" that act as downloadable content or "Common" Group for those that are shared between levels that's included in the base installation? All these PlayableDirectors in a lot of Scenes and Prefabs cause a ton of dependencies being tracked as stuff going unnecessarily into our "Common" group, bloating the base game install and unintentionally diminishing the downloadable content bundles. Also, memory management suffers similarly, with a lot of unintentionally Common stuff being unnecessarily kept in memory on devices that can't spare it.