Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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,313
    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.
     
unityunity