Search Unity

Question Find PlayableDirector from TrackAsset

Discussion in 'Timeline' started by Midonk, May 3, 2022.

  1. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    Hello everyone ! Let me explain my problem :
    I am actually scripting a custom LocalizedAudioTrack with the Timeline and the Localization packages.
    I am inheriting the built-in AudioTrack.
    I need to setup the correct Locale when the track enables. For this, I set the correct Locale, changes the clips with the AssetTable and then rebuild the graph of the related PlayableDirector but I'm stuck with this.
    I can't find a way to fetch the director when the track enables.
    I know I can retrieve it from a playable but I have...well...no access to any playable in the TrackAsset or OnEnable right ? Maybe there is something I am missing with the playables ?
     
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I think I recall you can only get the playable in the create method - save it to a private member variable for use in later functions
     
  3. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    The problem is that I tried to ovrride the method, put a log in it to see when Unity calls it but it never logged anything...
     
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Sorry, re-reading your original post. I am trying to understand which class you are referencing things in. There are some great videos on Timeline and custom tracks in YouTube. It is complicated by the fact that Timelines are not tied to an instance (so you can reuse them). So there are the bindings in a scene (binding the timeline to real objects), and you have to write behaviors to do all the track mixing etc. So the track asset and track clips are "templates" (all the settings for) the actual work, but they don't really do work themselves. Behaviors do the real work (getting values copied from the "template" clips), and mixers are needed if you want blending of behavior properties.

    From re-reading the above, it was not clear to me whether you are trying to put the code in the right class. That is, are you only overriding TrackAssets, or are you updating the behaviors and mixers etc that goes with it? It may very well be you have to make the locale one of the properties of the clip that get copied into the behavior class for it to use when its really doing the work... if that makes sense!

    PS: I have written a couple of custom tracks, but they still make my head spin with the number of concepts and terminology / class names that do not leap out to me intuitively.
     
  5. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    Yup for more details I created the four required classes :
    - public class LocalizedAudioTrack : AudioTrack
    - public class LocalizedAudioBehaviour : PlayableBehaviour
    - public class LocalizedAudioClip : AudioPlayableAsset
    - public class LocalizedAudioTrackMixer : PlayableBehaviour

    The question here is : if I want to retrieve the PlayableDirector resolving the instance of the track (here the LocalizedAudioTrack) when it get enabled, what should I do ?
     
  6. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Hopefully someone with deeper knowledge jumps in, but until then...

    What I was trying to work out is what does "enabled" mean. I say this from the point of view is there is the editor preview mode where you can jump the playhead around, and Play mode with seek APIs as well. I was wondering if it is just the job of behaviors to cope with starting from anywhere, and concepts like "enable" is just something you have to keep track of with your own state variables. "This field is null, so I will initialize it now" rather than "I want to run this code with a playable before really starting rendering frames".

    For example, I had problems with markers being used to change state in a Timeline (I was changing the skybox). I would move the playhead into the middle of the Timeline and all the initialization at the start did not kick in. So I changed my mental model to having clips. The clip behavior would optimize to say "if the current skybox is not what I want, change it". There was no "before you start", it was all "get the state to what I want it to be now". Doing that I guess I avoided the "OnEnable" problem. I understand however that Locale is not something that is going to change mid Timeline, so it may feel wasteful.

    Is that a long winded way of saying "sorry, I don't know the answer to your question, I don't do it that way"...