Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved How to modify an animating property value with manipulator in timeline?

Discussion in 'Timeline' started by sans108, Dec 20, 2021.

  1. sans108

    sans108

    Joined:
    Apr 1, 2021
    Posts:
    13
    Hi,
    I Create a custom timeline track with recording system. When I started to recorded it ,and modified the properties on the inspector, It worked perfectly.

    upload_2021-12-20_20-6-45.png

    Then I created a manipulator on the scene view via script, and try to use it to modified properties, but it seems didn't work.

    upload_2021-12-20_20-14-32.png


    Here is my code.
    Code (CSharp):
    1.  
    2.  
    3.     [CustomEditor(typeof(CameraClip))]
    4.     public class CameraClipInspector : Editor
    5.     {
    6.         .....other code.....
    7.  
    8.         private void OnSceneGUI(SceneView sceneView)
    9.         {
    10.             DoManipulators();
    11.         }
    12.  
    13.         private void DoManipulators()
    14.         {
    15.             var clip = target as CameraClip;
    16.  
    17.             if (null == clip || null == clip.BindingCamera)
    18.                 return;
    19.  
    20.             var camTrans = clip.BindingCamera.transform;
    21.             if (camTrans == null || _mode == OffsetEditMode.None)
    22.                 return;
    23.  
    24.             Vector3 position = camTrans.position;
    25.             Quaternion rotation = camTrans.rotation;
    26.  
    27.             EditorGUI.BeginChangeCheck();
    28.             if (_mode == OffsetEditMode.Position)
    29.             {
    30.                 position = Handles.PositionHandle(position, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : rotation);
    31.             }
    32.             else if (_mode == OffsetEditMode.Rotation)
    33.             {
    34.                 rotation = Handles.RotationHandle(rotation, position);
    35.             }
    36.  
    37.             if (EditorGUI.EndChangeCheck())
    38.             {
    39.                 var window = TimelineWindow.instance;
    40.                 if (null != window && null != window.state && window.state.recording)
    41.                 {
    42.                     clip.template.position = position;
    43.                     clip.template.eulerAngles = rotation.eulerAngles;
    44.  
    45.                     window.state.rebuildGraph = true;
    46.                     window.RebuildGraphIfNecessary(true);
    47.                 }
    48.             }
    49.         }
    50.  
    51.         .......other code......
    52.     }
    53.  
    54.  
    Code (CSharp):
    1.  
    2.     [Serializable]
    3.     public class CameraClip : PlayableAsset
    4.     {
    5.         public CameraBehaviour template = new CameraBehaviour();
    6.  
    7.         public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    8.         {
    9.             var playable = ScriptPlayable<CameraBehaviour>.Create(graph, template);
    10.             return playable;
    11.         }
    12.  
    13.     }
    14.  
    Code (CSharp):
    1.  
    2.     [Serializable]
    3.     public class CameraBehaviour : PlayableBehaviour
    4.     {
    5.         public Vector3 position = Vector3.zero;
    6.         public Vector3 eulerAngles = Vector3.zero;
    7.         public float fov = 20f;
    8.     }
    9.  
    I hope I was clearly explained the issue, If someone know the answer, please help me.
     
    Last edited: Dec 20, 2021
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Keyframe recording works by intercepting property modifications to serialized objects (the thing that inspectors manipulate). If your code modifies the transform directly, your changes won't be picked up.
     
  3. sans108

    sans108

    Joined:
    Apr 1, 2021
    Posts:
    13
    @DavidGeoffroy I tried to modify SerializedProperty and it worked! Thank you so much!