Search Unity

Binding Transform Tweenclips' parameters at Runtime

Discussion in 'Timeline' started by zIyaGtVm, Jun 25, 2018.

  1. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Hi, I'm using [Transform Tween Track] in [Default Playables] asset to move Player's transform position.
    Could I set the "Start End" values through code in runtimes?
    because I want to reuse this timeline assets on different targets.

    For example, I have several doors, which can be triggered by Player,
    each one has several clips to move player step by step.

    What should I do to access different clips' "start location" "end location" like ClipA ClipB ClipC on one Track in the picture below?

    Appreciate any help I can get, Thanks!

    tween clip.png
     
    Last edited: Jun 25, 2018
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
  3. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Really thanks for telling me that! May I ask more about how to get the target clip that I need?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Here's an example of how to set all exposed references to the same target (class/variable names may not be accurate....)

    Code (CSharp):
    1. // grab the timeline asset from the playable director
    2. var timelineAsset = playableDirector.playableAsset as TimelineAsset;
    3.  
    4. // get the list of output tracks of the target type
    5. var tracks = timelineAsset.GetOutputTracks().OfType<TransformTweenTrack>();
    6. foreach (var track in tracks)
    7. {
    8.     Debug.Log(track.name);
    9.     // go through all the clips
    10.     foreach (var clip in track.GetClips())
    11.     {
    12.         Debug.Log(clip.displayName);
    13.         var tweenClip = clip.asset as TransformTweenClip;
    14.         if (tweenClip != null)
    15.         {
    16.             // grab the property name from the clip
    17.             PropertyName prop = tweenClip.startLocation.exposedName;
    18.            
    19.             // assign the object through the playable director
    20.             playableDirector.SetReferenceValue(prop, targetObject.transform);
    21.         }
    22.     }
    23. }
     
  5. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    It's so kind of you to show me the example!
    Thanks and I'll try it immediately !:)
     
    Last edited: Jun 28, 2018
  6. ILightMaster

    ILightMaster

    Joined:
    Jun 18, 2018
    Posts:
    3
    Hi this is exactly what i want to do :

    director.SetReferenceValue(ttc.startLocation.exposedName, data.startingPos);
    director.SetReferenceValue(ttc.endLocation.exposedName, data.endingPos);
    However my exposed reference name are identically equal to 0

    so it changes both fields.

    Shouldn't they be serializefields or when we create a clone of the playable recalculated with a different id
     
    Last edited: Jul 9, 2018
  7. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    177
    You will need to initialize the exposed reference before setting its value:
    Code (CSharp):
    1. ttc.startLocation = UnityEditor.GUID.Generate().ToString();
    2. ttc.endLocation = UnityEditor.GUID.Generate().ToString();
     
  8. ILightMaster

    ILightMaster

    Joined:
    Jun 18, 2018
    Posts:
    3
    It's working but i'm not sure if i've done it properly.

    Just to be clear i'm using a control track to manage several instances of the same timeline asset and i'm settings up the bindings and the reference value of my tracks at runtime.
    For example i have a timeline where the player's characters are joining the field, but i don't know how many characters were selected by the player then they will taunt/cheer ( all of my timelines asset are stored in a sciptable object as a database of timelines )

    So to make it work i added the initialization of those properties of each one of my stored timeline used in my scene. (before their instantiation )

    Its seems that it will be expensive. How could i do this as a default behavior, like before their serialization maybe i'm sorry i'm not an expert ? In the transform tween track or clip, or i the playable asset ? Also after play mode, inspectors of my tracks seem to be broken.

    In inspector debug view there are two main differences, once is that my asset id changed
    and the other one is that my main playable director kept all my scene bindings and exposed references. how can i clear them.

    EDIT : https://forum.unity.com/threads/swa...e-timelineassets-per-playabledirector.487520/
    This thread was usefull for me
     
    Last edited: Jul 10, 2018