Search Unity

Get Behavior to update properties in Editor

Discussion in 'Timeline' started by Solovykh, Dec 7, 2017.

  1. Solovykh

    Solovykh

    Joined:
    Aug 28, 2017
    Posts:
    59
    How do I get the value of N to update in the editor?

    Code (CSharp):
    1. [System.Serializable]
    2.     public class IncrementPlayableBehavior : PlayableBehaviour
    3.     {
    4.         public int n;
    5.  
    6.         public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    7.         {
    8.             n = n + 1;
    9.         }
    10.  
    11.     }
    12.  
    13.     [System.Serializable]
    14.     public class IncrementClip : PlayableAsset
    15.     {
    16.         public IncrementPlayableBehavior incrementPlayableBehaviorTemplate = new IncrementPlayableBehavior();
    17.  
    18.         public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
    19.         {
    20.             return ScriptPlayable<IncrementPlayableBehavior>.Create(graph, incrementPlayableBehaviorTemplate);
    21.         }
    22.     }
    Code (CSharp):
    1. [CustomEditor(typeof(IncrementClip))]
    2.     public class IncrementClipEditor : Editor
    3.     {
    4.         private SerializedProperty n;
    5.  
    6.         private void OnEnable()
    7.         {
    8.             n = serializedObject.FindProperty("incrementPlayableBehaviorTemplate.n");
    9.         }
    10.  
    11.         public override void OnInspectorGUI()
    12.         {
    13.             serializedObject.Update();
    14.  
    15.             EditorGUILayout.PropertyField(n);
    16.  
    17.             serializedObject.ApplyModifiedProperties();
    18.         }
    19.     }
    Do I just want to set a public variable in my asset that stores the behavior attached to the playable?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The PlayableBehaviour in your PlayableAsset is simply a template. When a timeline is played, and/or evalutated, a clone of that template is made so changing any values in Prepare or Process Frame will not have any effect.

    You can either change the templates values from an Editor, or, like you stated, have a copy in the PlayableAsset that gets assigned.