Search Unity

Curious, why does playable.GetInputCount() return 0 for a non-MixerBehaviour?

Discussion in 'Timeline' started by Jamez0r, Jan 24, 2021.

  1. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    206
    Just spent a couple hours trying to figure out why using playable.GetInputCount() in ProcessFrame() was returning 0 regardless of how many clips I had in the track.

    I was using a regular (non-Mixer) PlayableBehaviour (aka my Track did not have a CreateTrackMixer() function set up). I set up a MixerBehaviour and now in the MixerBehaviour's ProcessFrame() it correctly shows the input count.

    Why is this? I don't need to do any mixing/blending for this Track. Isn't the GetInputCount() just supposed to return the number of clips on the track?

    I'm just trying to better understand what is going on here, thanks for any help!
     
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    The input count is the number open ports on the underlying playable. Your clip playables have zero, because they don't need to mix anything. Your track mixer has N (number of clips) because it has N clips connected.

    GetInputCount doesn't return the number of clips. Well it can do so but that's an implementation detail. We could change the implementation and only use two ports.
     
  3. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    206
    Thanks for the response! I think I'm understanding things better now.

    Non-MixerBehavior:
    -is a behavior that is per-clip, not per-track
    -doesn't call ProcessFrame unless its clip is currently active

    MixerBehavior:
    -is a single behavior for the entire track
    -calls ProcessFrame always, and has the InputCount information & weights


    What I was trying to do was to 'trigger something happening' on the first frame that a clip was active. I achieved this with the MixerBehavior by keeping track of the weights for each of the clips (via the InputCount) and triggering the thing when the weight went from 0 to 1.

    Is there a suggested way for doing this with the normal non-mixerBehaviors? I could simply have a "bool hasBeenTriggered" and then reference & set that when ProcessFrame is called, but I'm not sure how the hasBeenTriggered bool would get reset - lets say if I was just scrubbing the timeline back and forth or something like that, I'm not sure how the bool could get reset?

    Thanks again for the help!
     
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Playables are meant to be straight media providers: you set them to a time, and they produce an output.

    If there is a need for more logic, it is usually solved by adding a layer on top.

    In this case, essentially, you would handle the start/stop detection at the track level. You could then add OnStart and OnStop methods to your clip playables and call them from the track when weights change. The easiest way to do so is to keep track of last frame's weights in an array and compare them to the new weights in PrepareFrame.
     
  5. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    206
    Perfect, thank you for the explanation!