Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple TrackClipType

Discussion in 'Timeline' started by Antoine_OSG, Apr 27, 2017.

  1. Antoine_OSG

    Antoine_OSG

    Joined:
    Sep 2, 2016
    Posts:
    43
    I've created a custom track to hold all the actions my characters will perform in timeline. I've made all these actions inherit from an absctract class called CharacterPlayable which itself inherits from ScriptPlayable
    I'd like to be able to add only these actions in my CharacterTrack, but I can't find a way to do this.
    Here are some snippets of my code :

    Code (CSharp):
    1. [TrackBindingType(typeof(Character))]
    2. [TrackClipType(typeof(CharacterPlayableAsset))] //Also tried with CharacterPlayable
    3.  
    4. public class CharacterTrack : PlayableTrack {
    5.  
    6. }
    Code (CSharp):
    1. [System.Serializable]
    2. public class LookAt : CharacterPlayableAsset {
    3.  
    4.     public ExposedReference<GameObject> Agent;
    5.     public ExposedReference<Transform> Target;
    6.  
    7.     public override PlayableHandle CreatePlayable (PlayableGraph graph, GameObject owner)
    8.     {
    9.         var handle = graph.CreateScriptPlayable<LookAtPlayable> ();
    10.         handle.GetObject<LookAtPlayable> ()._agent = Agent.Resolve (graph.resolver);
    11.         handle.GetObject<LookAtPlayable> ()._target = Target.Resolve (graph.resolver);
    12.         return handle;
    13.     }
    14. }
    Code (CSharp):
    1. [System.Serializable]
    2. public class LookAtPlayable : CharacterPlayable {
    3.  
    4.     public Transform _target;
    5.     public GameObject _agent;
    6.  
    7.     public override void ProcessFrame (FrameData info, object playerData)
    8.     {
    9.         _agent.transform.LookAt (_target);
    10.     }
    11.  
    12. }
    I also have an other class build on the same method as LookAt that also inherits from CharacterPlayableAsset.
    When I right clic on my CharacterTrack in Timeline, I expect to see both methods I've created, but I only get the option to add a CharacterPlayableAsset (which is abstract), and I get the following error when I do so :
    I have also tried to add one "TrackClipType" per class I want to be able to select, but it only keeps the last one.

    How can I solve this?
     
  2. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    648
    Did you ever figure this out? I also need the ability to specify which sub classes can go into a track.
     
  3. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    648
    I'm starting to think this is a bug ... the documentation uses plural for "Scriptplayables" and "clips", which leads one to assume you should be able to add multiple trackcliptypes using this. If this is a bug, can we get a confirmation on this, so we can leave it as is in the code for now and assumably have it fixed in a coming update?

    From the docs: "Specifies the type of PlayableAsset or ScriptPlayables that this track can create clips representing.

    This is required for custom track assets to specify the type of clips to create."
     
  4. Keepabee

    Keepabee

    Joined:
    Jul 12, 2012
    Posts:
    58
    Having similar problems. I'm trying to add multiple Clip types to the same Track in very much the same idea.

    I don't think it's a bug - neither Editor-internal Timeline Tracks nor the DefaultPlayable Track examples show a single Track that would have this kind of behaviour that it would take multiple Clip types (Animation and Audio tracks have multiple context click menuitems, but they are only shortcuts to select a different source for the setup of single-type the Audio/Animation type Playables for their respective tracks).

    For now I'm planning to make some kind of Clip class to hold all kinds of parameters and then inheriting that class just to have different PropertyDrawers that expose only desired fields to the Inspector - I'd much rather just inherit the base class used as the TrackClipType and setup the parameters neatly per child class, but I suspect Unity's serialization would lose sight of the data stored in child class type if the Clip stores a serialized field that is the type of the base class.
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    This appears to be a bug in the UI. The drop down menu is only picking up the first clip type specified.

    I've logged a bug for this, hopefully it will be fixed soon.
     
  6. blackbookuser

    blackbookuser

    Joined:
    Aug 29, 2017
    Posts:
    5
    What is the timeline for this fix? We are running into the same problem now in trying to extend the timeline in order to reduce boilerplate stuff.
     
    DGordon likes this.
  7. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    648
    Seconding the request to know about its status, or an understanding how how to find the bug that was apparently logged?

    Very curious what way we're supposed to go about tracking this, thanks!
     
  8. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Yes, it is working in (at least) 2019.2. You can specify multiple TrackClipType attributes, or use a base class, or use an interface.
     
    blackbookuser and DGordon like this.
  9. andrewnoon

    andrewnoon

    Joined:
    Nov 19, 2018
    Posts:
    2
    Should it be possible to use an interface for the TrackBindingType attribute as with TrackClipType above? In 2019.2.19f1 the track binding disappears when specifying an interface, so I'm forced to create an additional concrete class to act as a binding.
     
  10. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Good question. I don't believe it is possible at the moment, as the requirement is the binding should be a Unity Object so that a reference to it can be serialized.

    But, should it, is a completely different story. I'd say it probably should, provided it's a Unity Object that implements that interface, and just an oversight on the use case on our part.
     
  11. andrewnoon

    andrewnoon

    Joined:
    Nov 19, 2018
    Posts:
    2
    It feels like it would be in keeping with the usage of TrackClipType, as they're often used side-by-side when creating a custom track. In fact I usually implement an interface anyway that I use when I access the track binding inside the playable behaviours and when I call out to my own logic. The Unity Object is only there as a go-between but it's always nice to eliminate unnecessary code!
     
  12. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    I really need to bind a track to an interface, may be there's some workaround for it?
     
  13. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Using a base class that derives from PlayableAsset is really the only way currently.

    You could also use ClipEditors (or TrackEditors) to display errors when the clip doesn't implement a particular interface as well. For example, have all your custom clips inherit from an abstract PlayableAsset-derived class, and have your custom track show errors when the clip type does inherit from an interface.

    Far from an ideal solution, as the user really shouldn't be able to add invalid clip types, but maybe there is something in there that helps your use case.
     
    palex-nx likes this.
  14. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Thanks! I think custom TrackEditor will work for my case.