event.SetTimeLinePosition() doesn't work?

Hello, :wave:

I’m currently working on replicating a video editing timeline in Unity. The goal is to be able to preview the cinematics of my video game directly with Unity’s editor. With this tool, I aim to avoid the back-and-forth between “cinematic editing” and “launching the game with the play button,” which consumes a lot of time during cinematic design.

Here’s a screenshot of the preview of my functional timeline.

In our project, we use FMOD, and I’m attempting to enable sound preview via my timeline, similar to a video editing software. I’ve managed to play the sound preview in the editor by using the PreviewEvent() function from the EditorUtils script, thus synchronizing the visual of my timeline with the preview. So, when the timeline cursor enters a sound block, the sound plays.

Now, I’m trying to move on to the second step: playing the sound at a certain given time. For this, I’ve consulted the documentation on your website as well as some posts on the forum:
FMOD doc
How to use settimelineposition ?

All the links provided suggest using the method: SetTimeLinePosition(), however, this doesn’t seem to work in my situation. In the search for a solution, I’ve written a simple script completely detached from my timeline to test if the method works. Here’s the script:

using UnityEngine;
using FMODUnity;

public class Test : MonoBehaviour
{
    public EventReference fmodEvent;
    public bool paused;
    private FMOD.Studio.EventInstance eventInstance;

    void Start()
    {
        GetComponent<FMODUnity.StudioEventEmitter>().Play();
        eventInstance = GetComponent<FMODUnity.StudioEventEmitter>().EventInstance;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            paused = true;
        }
        if (Input.GetKeyUp(KeyCode.UpArrow) && paused)
        {
            paused = false;
            eventInstance.setTimelinePosition(1500);
            eventInstance.getTimelinePosition(out int currentPosition);
            Debug.Log(currentPosition);
            eventInstance.start();
        }
    }
}

As you can see, I’ve added a Debug.Log to verify if the setTimelinePosition() method executes correctly, and its result is 0. The method did not position the timeline at 1500 milliseconds.

After many hours of research and with the limited resources available for developers on the FMOD tool, I can’t find any solution. Did I use the method correctly? Did I forget to do something? Can anyone help me? :slight_smile:

Hi,

The issue may be trying to call setTimelinePosition() on an event that is currently not playing. Most of our functions will return and FMOD.RESULT. Adding a result to the eventInstance.setTimelinePosition(1500); may provide more information why the function is not behaving as expected.

Rather than stopping the event in the if (Input.GetKeyDown(KeyCode.UpArrow)){} statement, I would suggest using setPaused() so the event instance stays valid while you are interacting with it.

Let me know if this helps. If not, please share the FMOD.RESULT of the setTimelinePosition() function call.

Hello, thank you for your answer! :pray:

I made the suggested modifications: replaced stop with pause and displayed the FMOD.RESULT of the methods.

Here’s the updated script:

using UnityEngine;
using FMODUnity;

public class Test : MonoBehaviour
{
    public EventReference fmodEvent;
    public bool paused;
    private FMOD.Studio.EventInstance eventInstance;

    void Start()
    {
        GetComponent<FMODUnity.StudioEventEmitter>().Play();
        eventInstance = GetComponent<FMODUnity.StudioEventEmitter>().EventInstance;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            eventInstance.setPaused(true);
            paused = true;
        }
        if (Input.GetKeyUp(KeyCode.UpArrow) && paused)
        {
            paused = false;
            FMOD.RESULT PosResult = eventInstance.setTimelinePosition(1500);
            FMOD.RESULT GetPosResult = eventInstance.getTimelinePosition(out int currentPosition);

            Debug.Log($"FMOD Pos Result : {PosResult}, FMOD GetPos Result : {GetPosResult}  , Desired pos : 1500, Current pos : {currentPosition}");

            eventInstance.getPaused(out bool isPaused);

            if(isPaused)
                eventInstance.setPaused(false);
            else
                eventInstance.start();
        }
    }
}

And here’s the result obtained from Debug.Log:

No change so far, I even tried putting the SetTimelineposition after the start but it didn’t make any difference.

1 Like

Thank you for sharing the updated code.

Could you please add FMODUnity.RuntimeManager.StudioSystem.flushCommands(); just after the setTimelinePosition() call, FMOD Engine | Studio API Reference - flushCommands. This function blocks the calling thread until all pending commands have been executed and all non-blocking bank loads have been completed. Ensuring we are setting the timeline before checking its position. Please check the value you are setting is high enough as it is being applied in milliseconds: FMOD Studio | Studio API Reference - setTimelinePosition and it may not be moving a noticeable amount.

Hope this helps

Thank you, the method works! Here’s the updated code and the result of the Debug.Log: :partying_face:

using UnityEngine;
using FMODUnity;

public class Test : MonoBehaviour
{
    public EventReference fmodEvent;
    public bool paused;
    private FMOD.Studio.EventInstance eventInstance;

    void Start()
    {
        GetComponent<FMODUnity.StudioEventEmitter>().Play();
        eventInstance = GetComponent<FMODUnity.StudioEventEmitter>().EventInstance;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            eventInstance.setPaused(true);
            paused = true;
        }
        if (Input.GetKeyUp(KeyCode.UpArrow) && paused)
        {
            paused = false;
            FMOD.RESULT PosResult = eventInstance.setTimelinePosition(8000);
            FMOD.RESULT FlushResult = FMODUnity.RuntimeManager.StudioSystem.flushCommands();
            FMOD.RESULT GetPosResult = eventInstance.getTimelinePosition(out int currentPosition);

            Debug.Log($"FMOD Pos Result : {PosResult}, FMOD GetPos Result : {GetPosResult}, FMOD flush result : {FlushResult} , Desired pos : 8000, Current pos : {currentPosition}");

            eventInstance.getPaused(out bool isPaused);

            if(isPaused)
                eventInstance.setPaused(false);
            else
                eventInstance.start();
        }
    }
}

According to the Debug.Log, the method seems to have worked but there is still an issue with the sound being heard. It is not updated. I don’t hear the repositioning of the sound but just a simple pause On/Off.

Is there an update/refresh method to execute to apply the changes made to the FMOD event? Or something like that?

Good to hear we are making progress. If you pass a much larger number (50000) to the setTimelinePosition() do you notice any difference?

Hey, I try with 50000, 100000 nothing changes.

1 Like

Thanks for checking that, could I please grab the audio file you are testing with? It can be uploaded to your profile, please note, that you have to register a project with us to upload files.

I submitted a project, it’s pending I guess

Hello,

I’m trying to create a project to transmit the file but I don’t understand how your system works at all. The project is being removed without any further explanation, so I am unable to send you the sound.

Moreover, I see that no solution has been provided to me during these last 2 days, thank you for your dedication. I will have to make do with what I have without resolving the issue.

Have a good day.

1 Like

Apologies for the confusion,

Your account has been set up now, and you can upload files to your profile if you want to.

Please let me know if there is anything else I can assist with.

I hope you’ll be able to provide me with a solution.

I could try to understand it myself, but there are no examples of configuration or demonstration of the setTimeLinePosition method. We don’t have access to it either. How do you suggest we, as developers, can adapt your wonderful tool to our needs?

I’ve provided you with the lambda script I use for my tests, as well as the audio file I use on my profile. So, why isn’t it working?

I can’t understand the problem because I don’t have access to how the method works.

Thank you for your patience and valuable feedback.
I have noted your concerns regarding the lack of examples with our team and we aim to keep improving our documentation and examples to ensure they meet the needs of developers like you.

I will DM you a profiler session using the provided code to set the timeline position of the Level 01 example event using the latest version of FMOD. Hopefully, this may show where the issue is coming from.