Hi, I’m making a custom playable where I need the reference to the referenced asset in the CustomTrackAsset. I don’t know if it’s possible because the ProcessFrame in the PlayableBehavior script gets called last, and I need that reference for the OnBehaviourPlay method which gets called before ProcessFrame.
Notice in the behaviour script OnBehaviourPlay, there is where I need the “GameObject” reference.
Clip:
public class CustomPlayableAsset : PlayableAsset
{
public bool toLoad;
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
{
var playable = ScriptPlayable<CustomPlayableBehavior>.Create(graph);
var scenePlayableBehavior = playable.GetBehaviour();
scenePlayableBehavior.toLoad = toLoad;
return playable;
}
}
Behavior:
[System.Serializable]
public class CustomPlayableBehavior : PlayableBehaviour
{
[Tooltip("true = load, false = unload")]
public bool toLoad;
GameObject gameObject;
//like the Update
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
gameObject = playerData as GameObject;
}
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
base.OnBehaviourPlay(playable, info);
if (gameObject != null)
{
//THIS DOESNT EXECUTE BECAUSE ITS NULL
}
}
}
Track:
[TrackColor(0, 0, 0)]
[TrackClipType(typeof(CustomPlayableAsset))]
[TrackBindingType(typeof(GameObject))]
public class CustomPlayableTrack : TrackAsset
{
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
return ScriptPlayable<CustomPlayableBehavior>.Create(graph, inputCount);
}
public override void GatherProperties(PlayableDirector director, IPropertyCollector driver)
{
base.GatherProperties(director, driver);
#if UNITY_EDITOR
var comp = director.GetGenericBinding(this);
if (comp == null)
return;
var so = new UnityEditor.SerializedObject(comp);
var iter = so.GetIterator();
while (iter.NextVisible(true))
{
if (iter.hasVisibleChildren)
continue;
driver.AddFromName(iter.propertyPath);
}
#endif
base.GatherProperties(director, driver);
}
}