Search Unity

Chaining Timelines

Discussion in 'Timeline' started by NDSno1, Dec 15, 2020.

  1. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Hi all.
    I'm trying to make a process simulation using Unity Timeline.
    I defined what component to be active and inactive in each step using activation track. However, each component state does not carry over to the next step, so when I play the Timeline Asset for one step, few component states are incorrect. For example:
    Initially all components are not active except for C.
    Step 1:
    - Activate component A until end of timeline
    - Activate component B until end of timeline
    - Component C active, then deactivate component C until end of timeline
    Step 2:
    - Component B active, then deactivate component B until end of timeline
    Step 3:
    - Component C deactivate, then activate component C until end of timeline
    The problem is here: when I run step 2 directly from the beginning, A and B are not active yet, because I don't have the activation track for them in step 2.
    So what I would like to do is the chain step 1 and step 2 together, so the state of step 1 is retained. Same with other steps, for example, when running step 5, step 1 to 4 is chained.
     
    Last edited: Dec 15, 2020
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If I understand correctly, you'd like to capture not just the activeness state of the objects but other values in components on the gameObjects under simulation.

    Timeline doesn't capture any state unless explicitly stated, typically through activation (active state) or animation tracks (any animatable property).

    One suggestion is to use Unity Recorder (available in the package manager). It can record animation clips for gameObject changes at runtime, and those animation clips can then be placed in timeline. It's simply a recording of the simulation, that can then be played back in timeline. The catch is the simulation values need to be serializable and able to be keyframed.

    The APIs of the gameObject recorder are also available, if you would prefer to customize the process to better suit your needs.
     
    NDSno1 likes this.
  3. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Thank you very much for the quick reply.
    No my problem is very simple, just the activeness of the gameObject, that's it :)
    I think my problem is that there are steps that do not involve some components. So the "outside" component state is not recorded. Also DirectorWrap.Hold mode that I chose might have something to do with this.
    For example:
    Step 1:
    - component A active at first, the deactivate until end of step
    - component B is deactive and not in timeline
    Step 2:
    - component B deactive at first, then active component B until end of step
    Step 3:
    - component A deactive at first, then active component A until end of step
    - component B active at first, then active component B until end of step
    Each Active Track I set post-playback state to Leave As Is.

    So when I try to run step 2, component B is fine, then it stays active (Director Wrap Hold). Then I run step 1, then component B will stay active because of the result from step 2. Is there a way to go around this?

    Finally I would like to apologize for any confusion because of my bad English explanation
     
    Last edited: Dec 16, 2020
  4. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Edit: Thank you for the help. I managed to do it by having a script to forward to the latest state of each timeline (step), then play from the start of the current timeline.
    However, I'm having a new problem. I need to play all timelines in sequence, meaning of step 1 is finished then step 1 starts immediately. Is there something in Director API to do that?
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    DirectorWrap.Hold may be the problem. It keeps repeatedly evaluating the timeline on the last frame, and causes post-playback state not to be applied. Sounds like it is better to set it to none so there is no conflict between timelines.

    There are several ways to sequence the timelines. One is making them nested timelines using a control track and simply assign their gameObjects to three consective control track clips.

    Another is to use Signals and the end of each timeline to trigger the playback of the next script.

    From the API, playableDirector contains an event when a timeline is stopped (only works if wrap mode is None), that can be used to chain them together.