Search Unity

Copying exposed references between directors

Discussion in 'Timeline' started by danbrani, Nov 11, 2018.

  1. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    Is there any way to copy exposed references from one director to another, without relying on any info about specific clip types?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Hmm... it appears there is no accessor for what values are actually stored. A couple options - you could use EditorUtility.CopySerialized to copy all serialized values. That might be overkill. Or you could use SerializedObject and SerializedProperties to do the copying and filter out the fields you don't want to copy.

    But there doesn't appear to be an API to access those specific table entries.
     
    danbrani likes this.
  3. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    I'm trying to do this at runtime, the goal is to avoid cloning the whole director and instead use a pre-instantiated one, copy the bindings and exposed references and finally play it.

    The use case is: I have an effect timeline that is supposed to play each time an enemy is hit, and I need to be able to play multiples of this timeline at the same time.

    Any tips how this could be done?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Ok, that's a good use case :)

    You can set the names explicitly on exposed references via script. For example, given a control track clip c, you can give the exposed references an explicit name

    ((ControlPlayableAsset) c.asset).sourceGameObject.exposedName = "Explosion";

    Then on your playable director(s), set that name explicitly.

    playableDirector.SetReferenceValue("Explosion", explosionGameObject).

    For track bindings, you can search for the tracks on the timeline with a given name, and set their binding:

    playableDirector.SetGenericBinding( FindTrackWithName(timeline), thingToAnimate);

    Then you can set all bindings with pre-fixed names and reuse a timeline.
     
    danbrani likes this.
  5. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    46
    Awesome thanks! This will work.

    It's possible to iterate through tracks and check the bindings so this part was not an issue, would be great if there was something similar for exposed references :D

    Thank you!