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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

How to edit the name of a track in the Inspector (Images included)

Discussion in 'Timeline' started by JustJunuh, Jul 26, 2022.

  1. JustJunuh

    JustJunuh

    Joined:
    Jun 3, 2015
    Posts:
    35
    On the left here, I have my custom track. On the right, I have an Activation Track.

    upload_2022-7-25_22-54-45.png

    Do I need to create a custom editor for renaming a track in the Inspector? I've been looking at the source code for ActivationTrack, and its editors, but I can't figure out what must be done.
     
  2. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    166
    You don't need a custom inspector to rename a track. For tracks that do not have a custom inspector, Timeline will automatically assign a default one, which makes it possible to edit the track name. Here's a custom track without a custom inspector:
    upload_2022-7-26_11-47-5.png

    However, if you need a custom inspector for your track, then the inspector loses the ability to change the name (as Timeline uses an internal method to override the standard inspector header UI):
    upload_2022-7-26_11-49-25.png

    If you want to get the ability to rename a track in your custom inspector, here's how you can do it:
    Code (CSharp):
    1. [CustomEditor(typeof(MyTrack)), CanEditMultipleObjects]
    2. public class MyTrackInspector : Editor
    3. {
    4.     protected override void OnHeaderGUI()
    5.     {
    6.         EditorGUILayout.Space();
    7.  
    8.         using (new GUILayout.HorizontalScope(EditorStyles.inspectorFullWidthMargins))
    9.         {
    10.             //draw the default track icon
    11.             GUILayout.Label(AssetPreview.GetMiniThumbnail(target), GUILayout.Width(40), GUILayout.Height(40));
    12.  
    13.             using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
    14.             {
    15.                 //get the name property of the selected track(s)
    16.                 SerializedProperty nameProperty = serializedObject.FindProperty("m_Name");
    17.  
    18.                 //draw a text field to edit the name property
    19.                 EditorGUILayout.PropertyField(nameProperty, GUIContent.none);
    20.  
    21.                 if (changeCheckScope.changed)
    22.                 {                  
    23.                     //apply changes: will record an undo operation
    24.                     serializedObject.ApplyModifiedProperties();
    25.  
    26.                     //refresh the timeline window to update the track name
    27.                     TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
    28.                 }
    29.             }
    30.         }
    31.     }
    32. }
    Which looks like this:
    upload_2022-7-26_11-35-13.png
     
    JustJunuh likes this.
  3. JustJunuh

    JustJunuh

    Joined:
    Jun 3, 2015
    Posts:
    35
    Thank you so much! For some reason, the default header for my custom tracks has the name uneditable. I'm on 1.5.7. Here's the code example. (No custom editor)
    Code (csharp):
    1.  
    2. [TrackColor(0.3882352941176471f, 0.7843137254901961f, 1f)]
    3. [Serializable]
    4. [TrackBindingType(typeof(TextAnimatorPlayer))]
    5. [TrackClipType(typeof(AnimatedTextClip))]
    6. public class AnimatedTextTrack : TrackAsset
    7. {
    8.     public override bool CanCreateTrackMixer() => true;
    9.     public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    10.     {
    11.         return ScriptPlayable<AnimatedTextMixer>.Create(graph, inputCount);
    12.     }
    13. }
    14.  
    That custom inspector solved my problem though :) I'm totally okay with just using that.
     
unityunity