Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#
Method group is Obsolete

PlayableBehaviour.PrepareData

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Obsolete PrepareData is obsolete. This method was invoked as part of the Playable delay mechanism, which has now been fully deprecated. This method is no longer invoked by Unity and will be removed in a future version. You can emulate this functionality by implementing your own delay mechanism as part of a PlayableBehaviour.

Declaration

public void PrepareData(Playable playable, FrameData info);

Parameters

Parameter Description
playable The Playable that owns the current PlayableBehaviour.
info A FrameData structure that contains information about the current frame context.

Description

This function is called during the PrepareData phase of the PlayableGraph.

Note: This method is obsolete and is not invoked by Unity anymore.

PrepareData is called as long as the playable is delayed.

using UnityEngine.Playables;

public class DelayedBehaviour : PlayableBehaviour
{
    public double Delay;
    public float LeadTime;
    private bool m_Started;

    public virtual void OnPrefetchData(Playable playable, FrameData info) {}

    public override void PrepareFrame(Playable playable, FrameData info)
    {
        if (m_Started) return;

        double remainingDelay = Delay - playable.GetTime();

        for (int i = 0; i < playable.GetInputCount(); i++)
        {
            var input = playable.GetInput(i);
            input.SetSpeed(0.0);

            if (LeadTime >= remainingDelay)
                InvokePrefetchData(input, info);
        }

        if (remainingDelay <= 0.0)
        {
            m_Started = true;
            for (int i = 0; i < playable.GetInputCount(); i++)
                playable.GetInput(i).SetSpeed(playable.GetSpeed());
        }
    }

    static void InvokePrefetchData(Playable playable, FrameData info)
    {
        if (typeof(DelayedBehaviour).IsAssignableFrom(playable.GetPlayableType()))
            ((ScriptPlayable<DelayedBehaviour>)playable).GetBehaviour()?.OnPrefetchData(playable, info);
    }
}