Search Unity

Proper way to manage multiple timeline ?

Discussion in 'Timeline' started by 009, Aug 14, 2017.

  1. 009

    009

    Joined:
    Nov 7, 2013
    Posts:
    14
    In my case, I'm using timeline to create animation for character skill, so I can manage all the collider and effects object in the same timeline. But, because I got multiple skill, I've created multiple playable asset and using script to assigning the Director to play them. But if I do this, I need to manually select the playable asset from "Playable" inspector when I need to edit the others timeline (Because I can't have multiple director component or playable asset) , it still works but doesn't seems like a proper way. (feels like cheating :3 )

    Did I miss out somethings important ? Or did I used a overpowered way ? Suggestion would be appreciate. Thanks
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You can edit the timelines by clicking on the timeline asset in the project window, but you won't be able to assign bindings, preview, or do anything that requires a scene context.

    Or each timeline can have it's own playable director component in the scene, and your script can just access the different directors.

    Those might be easier workflows.
     
  3. 009

    009

    Joined:
    Nov 7, 2013
    Posts:
    14
    Ya that sounds more easy to manage, thanks for the suggestion : )
     
  4. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    Since there is a Timeline selection dropdown I thought you would be able to select all compatible Timelines, but I guess defining compatibility is not easy, so we end up with only one choice possible.

    upload_2018-6-24_19-43-0.png


    That still seems the ideal place to put other Timeline candidates (think the Animator view where all Animations used at least once in the Animator Controller can be switched to with a dropdown).

    I was watching this video:

    and there is an ellipse just when the speaker changes Timeline. It looked like he uses a dropdown but now I'm almost sure there is an ellipse because he had to drag and drop the Timeline and it took some time to find the asset in the Project.

    That said, I understand the difference between the Animation dropdown, which doesn't change the state of the object (the Animator Controller remains the same) and the Timeline dropdown I suggest, which would change the TImeline reference on the active Playable Director and make it dirty. So I guess using the Playable object picker is the more appropriate way since it shows to the user that the object's state has changed.

    However, I still wonder why there is a Timeline dropdown at all, if only one can be selected at a time?
     
    olejuer likes this.
  5. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    211
    Just like @009 I am using timelines for character actions. Orchestrating animations, sounds, effects and also logical events at specific points in time is great this way. But editing a set of a few dozen skills becomes time consuming, because switching between them requires me to find the asset in the project view first. I would love it when the workflow here could be improved.

    Individual PlayableDirectors for each skill is not an option for me. The PlayableDirector must be attached to the character, because it is instantiated from a prefab. Selecting the timeline asset in the project view prevents playback. And as @seant_unity says, references cannot be edited this way, because the PlayableDirector holds that state.

    As @huulong says, there is a dropdown which could offer this possibility. Currently, you can use it to switch between different PlayableDirectors that are in the scene/prefab. The PlayableDirector already holds a list of PlayableAssets for which it defines bindings. So it should be possible to make those accessible via the dropdown, or am I wrong?
     
    Last edited: Apr 6, 2020
  6. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    What I'd do is make a custom 'skill editor' editor window that displays a list of playable directors in the scene, you can use GameObject.FindObjectsOfType<PlayableDirector>() to get a list of playable directors and use this as a shortcut picker
     
  7. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    211
    Hi, thanks for your reply.
    Well, there is only one PlayableDirector, but it will play different timeline assets, using PlayableDirector.Play(PlayableAsset).
    I would love to build a custom editor window, that would show all PlayableAssets that the selected PlayableDirector has bindings for. The PlayableDirector does have bindings for all these PlayableAssets. This is serialized as m_SceneBindings and from the respective guids it should be possible to figure out the PlayableAssets. Only I don't know how to access that, otherwise I could help myself. The dropdown in the timeline window unfortunately only offers those that are currently assigned to some PlayableDirector in the scene. But I need those that have configured bindings but are not currently assigned to any PlayableDirector. This would be similar to the Animation window where there is a dropdown with all Animations that are assigned to some state of the Animator.
    Does this make sense?
     
  8. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    a playable director can only have bindings to a single asset at a time - if you are dynamically swapping the asset that it is bound to then you'd want to do basically the same thing that I suggested, except instead of storing a list of playable directors, you'd store a list of the 'skill assets' and dynamically update the playable director's asset entry and refresh the timeline window to display the updated asset info.

    The bindings themselves however are stored in the scene / prefab so you'd have to store the 'last known bindings' and reconnect them dynamically as well (which is definitely doable in theory).

    Either way, this would require custom tooling for this use case.
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Actually, a playable director retains bindings from all timelines that have been assigned to it, but the inspector only displays the bindings for the currently assigned timeline, unless you use the debug inspector. The retaining of the bindings was intentional for the use case of swapping timelines easier - but this can also be problematic in that there are hidden asset references.

    And, as Mike points out, if you are using prefabs it only retains bindings for items in the prefab.

    And as @olejuer points out, there is no API to query which bindings it has. If you know the timeline asset, the binding key to GetGenericBinding is simply the track, and you can iterate on those using timelineAsset.GetOutputTracks(), even if the timelineAsset is not currently assigned as the main timeline.

    An additional Monobehaviour / window that holds all the timelines might work to quickly switch timelines on a playable director - I'm not sure if the timeline editor will handle the case where the timeline asset is swapped out on the playable director. Might need to unload/reload the playable director in the timeline editor for it to update properly.
     
    olejuer likes this.
  10. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    211
    Hi,

    thank you @seant_unity ! With that information I was able to extend the inspector of PlayableDirector to show all TimelineAssets it has bindings for. Here it goes, works like a charm so far

    Code (CSharp):
    1. public class PlayableDirectorInspector : UnityEditor.Editor
    2. {
    3.     private TimelineAsset[] _timelineAssets;
    4.  
    5.     public override void OnInspectorGUI()
    6.     {
    7.         base.OnInspectorGUI();
    8.         EditorGUILayout.LabelField("Configured Timelines", EditorStyles.boldLabel);
    9.         var playableDirector = serializedObject.targetObject as PlayableDirector;
    10.         if (playableDirector == null) return;
    11.         _timelineAssets = _timelineAssets ?? Resources.FindObjectsOfTypeAll<TimelineAsset>();
    12.         TimelineAsset[] configuredTimelines = _timelineAssets
    13.             .Where(timelineAsset => timelineAsset.GetOutputTracks()
    14.                 .Any(track => playableDirector.GetGenericBinding(track) != null))
    15.             .ToArray();
    16.  
    17.         foreach (TimelineAsset timelineAsset in configuredTimelines)
    18.         {
    19.             GUILayout.BeginHorizontal();
    20.             GUILayout.Space(20);
    21.             GUI.enabled = false;
    22.             EditorGUILayout.ObjectField(timelineAsset, typeof(TimelineAsset), false);
    23.             GUI.enabled = true;
    24.             if (GUILayout.Button("Select"))
    25.             {
    26.                 playableDirector.playableAsset = timelineAsset;
    27.                 TimelineEditor.Refresh(RefreshReason.ContentsModified);
    28.             }
    29.  
    30.             GUILayout.EndHorizontal();
    31.         }
    32.     }
    33. }
     
    seant_unity likes this.
  11. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    211
    Looks like this and can be used to quickly navigate to the TimelineAsset or select it, which refreshes the Timeline window:
    upload_2020-4-7_15-17-28.png
     
    tenconmar and seant_unity like this.
  12. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    nice! very cool
     
  13. santhmithran

    santhmithran

    Joined:
    Aug 11, 2018
    Posts:
    4
    Proper way to manage multiple timeline ?
    The answer cannot understand for me. Pls anybody show a answer in flow diagram or any video. pls, help me guys
     
  14. santhmithran

    santhmithran

    Joined:
    Aug 11, 2018
    Posts:
    4
    unity technologies pls next time upload a videos to give a proper explanation.Because the beginners are very struggle for your explanation.
     
    carlself likes this.
  15. omechano

    omechano

    Joined:
    Sep 12, 2014
    Posts:
    24
    wtf
     
    tenconmar and Tehenauin like this.