Is it possible to have a playable behavior reset after playback in editor mode?

I’ve written a playable behavior that sets the cinemachine priority. If you play the clip in editor mode, the change is made permanently, and you have to go manually change it back. I was wondering if there was a hook somewhere to allow me to reset the value if playback stops in editor mode?

Or maybe it’s as simple as that? I need to check if playback is in editor mode somehow, if so cache the original value, and reset on stop?

It sounds like you need to put the priority value into preview mode. If your PlayableAsset implements IPropertyDriver, the GatherProperties callback will be called when timeline goes into preview mode. When timeline stops previewing, the value will be restored to it’s scene value.

I think you’ll want something like the following - I’m assuming “m_Priority” is the serialized name of the property you want to preview.

public void GatherProperties(PlayableDirector director, IPropertyCollector driver)
{
    if (director == null)
        return;

    // use this if the track has a cinemachine virtual camera bound
    driver.AddFromName<CinemachineVirtualCameraBase>("m_Priority");
   
    // use this if you are using exposedReferences
    var cam = director.GetReferenceValue(m_ExposedReference) as CinemachineVirtualCamera;
    if (cam != null)
        driver.AddFromName<CinemachineVirtualCameraBase>(cam.gameObject, "m_Priority");
}
2 Likes

Excuse me where is the IPropertyDriver ?

Is there somewhere in documentation somewhere mentioned how to restore values when finishing doing preview ?

Also I have viewed this tutorial

https://www.youtube.com/watch?v=-bptgHPebDw

at 4:50 he is using firstFrameHappened variable, is this ugly way of restoring state the valid one ?