Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. 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
  3. 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

Help Wanted Timeline Animatable Property In Custom Inspector?

Discussion in 'Timeline' started by JoelLB, Jun 29, 2020 at 5:17 PM.

  1. JoelLB

    JoelLB

    Joined:
    Oct 9, 2019
    Posts:
    18
    Hi All,

    I have two scripts, one which displays the user properties in a custom inspector editor and another manages the properties - however these values are not displayed to the user. I've drawn up a simple version of my current setup below. I'm trying to the properties not shown to the user animatable on the timeline via the sliders which are shown to the user. However I can't seem to get them to keyframe. Any ideas or tips to why it isn't working? - In the example below- I want to animate selectedCategory on the timeline when the user changes the slider position.

    Custom Inspector Editor:
    Code (CSharp):
    1. [CustomEditor(typeof(LightingObjectControl))]
    2. public class GDTF_LightingControlInspectorEditor : Editor
    3. {
    4. private LightingObjectControl lightingObjectControlTarget;
    5. lightingObjectControlTarget.categoriesHolder.selectedCategory = (int) GUILayout.HorizontalSlider(lightingObjectControlTarget.categoriesHolder.selectedCategory, 0, 100);
    6. }
    Script To Manage Values:
    Code (CSharp):
    1. [Serializable]
    2. public class LightingObjectControl : MonoBehaviour
    3. {
    4.     // Editor Window Variables
    5.     public CategoryHolder categoriesHolder;
    6.     [Button("GenerateCategory")] //Button is part of ODIN.
    7.     public void genCat(){
    8.     CategoryHolder categoriesHolder = new CategoryHolder();
    9.     categoriesHolder = 0;
    10.     }
    11.     [Serializable]
    12.     public struct CategoryHolder
    13.     {
    14.         public Category[] Categories;
    15.         public int selectedCategory;
    16.     }
    17. }
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,309
    To allow keyframing it's required to use GUILayout methods that take a SerializedProperty, or wrap them in a BeginProperty/EndProperty block - see the example here.
     
  3. JoelLB

    JoelLB

    Joined:
    Oct 9, 2019
    Posts:
    18
    Is there any more information or help docs about getting custom fields to auto record onto a timeline? I've implemented what @seant_unity suggested, however by changing the slider it doesn't add a keyframe.

    Code (CSharp):
    1.  
    2. //Get the SerialisedObject that contains the value - lightingObjectControlTarget.Fixture.dmxChart.dmxChannels[dmxChanNumber].value
    3. SerializedObject objSer = lightingObjectControlTarget.getFixtureSO();
    4.                 SerializedProperty tempprop = objSer.FindProperty("dmxChart").FindPropertyRelative("dmxChannels").GetArrayElementAtIndex(dmxChanNumber).FindPropertyRelative("value");
    5.                 /
    6.                 EditorGUI.BeginProperty(EditorGUILayout.GetControlRect(), GUIContent.none, tempprop);
    7.                 EditorGUI.BeginChangeCheck();
    8.                
    9.                 int newVal =
    10.                         (int) GUILayout.HorizontalSlider(
    11.                             tempprop.intValue, 0,
    12.                             lightingObjectControlTarget.Fixture.dmxChart.dmxChannels[dmxChanNumber].maxValue);
    13.                 if (EditorGUI.EndChangeCheck())
    14.                 {
    15.                     tempprop.intValue = newVal;
    16.                 }
    17.  
    18.                 objSer.ApplyModifiedProperties();
    19.                
    20.                 EditorGUI.EndProperty();
    21.  
     
unityunity