Timelines - Event Track

Since timeline track coloring works per type, I’ve wanted to just extend the existing classes:

FMODEventTrack / FMODEventTrackEditor

and change the color via class attributes, but I’m getting an exception which originates from unity native code (unsupported type), I’m assuming it’s track binding related since type is now FMODEventTrack2.

Any idea if there is a workaround?

Our devs would just like a visual distinction between multiple event tracks…

Unfortunately, you cannot dynamically adjust timeline track color via class attributes. I believe this is a limitation with Unity - while you can change the color in the FMODEventTrack script by changing the appropriate class attribute (i.e. via assigning to [TrackColor(0.066f, 0.134f, 0.244f)]), you cannot set it dynamically.

That said, you can use UnityEditor.Timeline.TrackEditor to accomplish this instead, which FMODEventTrackEditor inherits from.

If you add the following line to the member declarations of FMODEventMixerBehaviour in FMODEventTrack.cs:

public Color color = new Color(0.066f, 0.134f, 0.244f);

and replace the code in FMODEventTrackEditor.cs with the following:

#if UNITY_TIMELINE_EXIST

using UnityEditor;
using UnityEditor.Timeline;
using UnityEngine;
using UnityEngine.Timeline;

namespace FMODUnity
{
    [CustomTimelineEditor(typeof(FMODEventTrack))]
    public class FMODEventTrackEditor : TrackEditor
    {
        private static readonly Texture2D icon = EditorUtils.LoadImage("StudioIcon.png");

        public override TrackDrawOptions GetTrackOptions(TrackAsset track, Object binding)
        {
            TrackDrawOptions options = base.GetTrackOptions(track, binding);
            options.icon = icon;
            options.trackColor = ((FMODEventTrack)track).template.color;

            return options;
        }
    }

    // This custom property drawer is here to draw the volume property at the
    // top level of the inspector, rather than in a Template foldout.
    [CustomPropertyDrawer(typeof(FMODEventMixerBehaviour))]
    public class FMODEventMixerVolumeInspector : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty volumeProperty = property.FindPropertyRelative("volume");
            SerializedProperty colorProperty = property.FindPropertyRelative("color");
            EditorGUILayout.PropertyField(volumeProperty);
            EditorGUILayout.PropertyField(colorProperty);
        }
    }
}

#endif

Then you’ll be able to set custom colors for each FMOD Event Track in your timeline. This is a very basic implementation, so your event playables on the track won’t inherit the color, but I’ve added this to our internal feature/improvement tracker. If you run into any issues, feel free to let me know.

tnx, will try it

Hi, just following up on this - did the provided script work for you, and address your need for a visual distinction between timeline event tracks? If not, was there any specific things that needs to be addressed?

Hei Louis,
yep, we are all good.

Thanks again.

1 Like