EventDescription length always zero

Hello,

I’m new to FMOD and I’m working on a game with Unity.

I created Single Event and then an Action Sheet, then I dragged and dropped an audio track there.

Screenshot:

This audio track is in this case a piece of a dialogue, e.g. a sentence of many.

Every audio has a text and I need to delete the current text in my UI when the current audio track is finished, and then go next…

This is the class handling some of this logic:

tnamespace Assets.Scripts.UI.Dialogues
{
    public class DialogPanelView : IDialogueView
    {
        // From constructor
        private GameObject dialogPanelPrefab;
        private Transform canvasTransform;
        private DialogSegmentData dialogSegmentData;

        // Others
        private GameObject instantiatedDialogPanel;

        public DialogPanelView(GameObject dialogPanelPrefab, Transform canvasTransform, DialogSegmentData dialogSegmentData)
        {
            this.dialogPanelPrefab = dialogPanelPrefab ?? throw new ArgumentNullException(nameof(dialogPanelPrefab));
            this.canvasTransform = canvasTransform ?? throw new ArgumentNullException(nameof(canvasTransform));
            this.dialogSegmentData = dialogSegmentData ?? throw new ArgumentNullException(nameof (dialogSegmentData));
        }

        public void Create()
        {
            GameObject dialogPanel = GameObject.Instantiate(dialogPanelPrefab);
            TMP_Text panelText = ComponentUtils.RequireFirstComponentInChildren<TMP_Text>(dialogPanel);
            panelText.text = dialogSegmentData.text;

            dialogPanel.transform.SetParent(canvasTransform, false);

            instantiatedDialogPanel = dialogPanel;
            RuntimeManager.PlayOneShot(dialogSegmentData.soundEvent);
        }

        public float GetWaitingTimeSeconds()
        {
            // TODO
        }

        public void Destroy()
        {
            GameObject.Destroy(instantiatedDialogPanel);
        }

    }
}

I want to implement the method float GetWaitingTimeSeconds() but it seems to return zero all the times.

I tried this:

            EventDescription eventDescription = RuntimeManager.GetEventDescription(dialogSegmentData.soundEvent);
            int totalTime;
            eventDescription.getLength(out totalTime);
            Debug.Log(totalTime);
            return totalTime;

And then this:

EventInstance instance = RuntimeManager.CreateInstance(dialogSegmentData.soundEvent);
            instance.getDescription(out EventDescription eventDescription);

            instance.start();

            int currentTime;
            FMOD.RESULT res = instance.getTimelinePosition(out currentTime);

            if (res != FMOD.RESULT.OK)
            {
                Debug.LogError("getTimelinePosition reported error: " + res);
            }
            Debug.Log($"currentTime = {currentTime}");

            int totalTime;
            FMOD.RESULT res2 = eventDescription.getLength(out totalTime);
            if (res2 != FMOD.RESULT.OK)
            {
                Debug.LogError("getLength reported error: " + res2);
            }
            Debug.Log($"totalTime = {totalTime}");
            return totalTime;

But no luck. Clearly I’m making a mistake. I know that this could be due to the fact that “there’s nothing in the timeline”, I’ve read in other threads. And while I understand the idea behind it, I don’t get how to properly implement this.

If you couldhelp me with the implementation of the method and give a brief explaination, I would be grateful.

Hi,

The issue here is indeed that the timeline is empty - Studio::EventDescription::getLength specifically returns the length of the timeline, but the event pictured has no timeline, and your asset is being played using an Action Sheet. While there are ways to get the length of the asset currently playing on an Aseets sheet, or to receive a callback when an instrument in an event has stopped playing, they are both more code-heavy than simply moving your single asset to a timeline, so I would recommend doing that if possible.

If using a timeline doesn’t fit for your use-case (e.g. if you’re planing on playing multiple dialogue assets using a single event), can you please provide me with a little more detail on your implementation of this audio behavior in FMOD Studio?

Hi, thanks for the answer!

How do I actually do what you say? That is, “moving the track to the timeline”, play it and get the length in seconds.

Regarding assets, no only one character at the time will speak. Does that answer your question?

If you click the + button next to the “Actions” tab in your event, you’ll be able to select “Add Timeline Sheet”. This will create a sheet on the event that uses the “Timeline” parameter of the event, which is a fancy way of saying it advances with the passage of time, triggering instruments that the playback position overlaps with. Since Studio::EventDescription::getLength returns the last point on the timeline with any sort of content, placing your asset on the timeline will cause the function to return the length of the asset. You can then remove the Action sheet from the event by right clicking on the “Actions” tab and selecting “Remove Sheet”.

For more info of Timeline Sheets, please take a look at the FMOD Studio Glossary entry on Timeline Sheets.

The more relevant question is whether you’ll be playing a single asset in each event, or whether you want to be able to play more than one asset in a single event, because using Studio::EventDescription::getLength in the manner we’re discussing doesn’t work with the latter.