Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get the Receiver (GameObject) assigned to a given Timeline Track, through script.

Discussion in 'Timeline' started by axxelart, Jul 27, 2022.

  1. axxelart

    axxelart

    Joined:
    Jun 28, 2020
    Posts:
    17
    Hey everyone!

    So, recently, I've encountered an issue with Timeline. I'm trying to reference the actual RECEIVER (GameObject) that can be assigned to a given track via the Timeline tab, as shown in the image below.

    upload_2022-7-27_16-55-30.png

    Before asking this question, I have indeed looked into all the different manuals, old and new, put up in regards of the Timeline Module, but I couldn't find anything that refers to the receiver assigned to the track.

    My goal here is to check if the track does NOT have a receiver assigned. If it doesn't, then it will be assigned the receiver accordingly.

    Thank you in advance for your help!
     
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    The receiver is referred to as a "binding". E.g. https://docs.unity3d.com/ScriptReference/Playables.PlayableBinding-sourceObject.html These bindings are stored in the scene hierarchy (not the track asset) from my understanding, allowing a timeline to be used by multiple game objects (e.g. if you can choose the character you are going to play with, the timeline can be used for all of them). Try having a look at PlayableDirector.GetGenericBinding() for example. There are also references, but I don't remember what they are exactly (blush).
     
  3. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    174
    That is correct, PlayableDirector.GetGenericBinding(track) will get the object bound to a track.

    PlayableAssets, including TimelineAsset, cannot directly contain references to game objects or components in the scene (just like any other asset). Instead, the PlayableDirector (which is a component that lives in a scene) stores those references.

    A PlayableDirector can store two types of references: objects bound to tracks and ExposedReference values.

    (Get/Set)GenericBinding is used to get/set a track's bound object.
    (Get/Set)ReferenceValue is used to get/set the object associated to an exposed reference.
     
    akent99 likes this.
  4. axxelart

    axxelart

    Joined:
    Jun 28, 2020
    Posts:
    17
    Exactly what I needed. Thanks a lot guys!
     
    julienb likes this.