How to change the loop state before playback using Unity code?

I know that in FMOD Studio, you can set up a loop by using Add Loop Region.

However, if the loop is not set in FMOD Studio, I would like to know how to enable or disable looping directly through Unity code.

Currently, I am playing the sound like this:
I will paste part of the code below.

private FMOD.Studio.EventDescription eventDescription;


if (eventDescription.isValid())
        {
            instance = GetInstance();
            await WaitForChannelGroup(instance);

            if (instance.isValid() && is3D)
            {
#if UNITY_PHYSICS_EXIST
                if (target.GetComponent<Rigidbody>())
                {
                    Rigidbody rigidBody = target.GetComponent<Rigidbody>();
                    RuntimeManager.AttachInstanceToGameObject(instance, target, rigidBody);
                    instance.set3DAttributes(RuntimeUtils.To3DAttributes(target, rigidBody));
                }
                else
#endif
#if UNITY_PHYSICS2D_EXIST
                if (target.GetComponent<Rigidbody2D>())
                {
                    var rigidBody2D = target.GetComponent<Rigidbody2D>();
                    RuntimeManager.AttachInstanceToGameObject(instance, target, rigidBody2D);
                    instance.set3DAttributes(RuntimeUtils.To3DAttributes(target, rigidBody2D));
                }
                else
#endif
                {
                    RuntimeManager.AttachInstanceToGameObject(instance, target);
                    instance.set3DAttributes(RuntimeUtils.To3DAttributes(target));
                }
            }
if (instance.isValid())
            instance.start();

        }


Hi,

An option may be using FMOD Engine | Studio API Reference - EventInstance::setTimelinePosition.
Something like this:

if (eventInstance.isValid())
{
    FMOD.RESULT result = eventInstance.getTimelinePosition(out int position);
    if (result == FMOD.RESULT.OK)
    {
        if (position >= 10000 /* This is the target loop point */)
        {
            result = eventInstance.setTimelinePosition(0); /* Loop back to the start of the event */
            if (result != FMOD.RESULT.OK)
            {
                Debug.LogError($"Failed to loop event with error: {result}");
            }
        }
    }
    else
    {
        Debug.LogError($"Failed to get timeline position: {result}");
    }
}

However, these isn’t a way to create a new FMOD Studio loop region from within Unity.

Hope this helps!

Thank you for your reply.
I don’t want to adjust the loop region.
There are some audio clips that I want to keep playing in Unity with looping enabled, even if no loop settings were made in the studio.
I would like to configure this via code.
Is it impossible?

I see, thank you for the clarification.

An option could be using the event callback FMOD Engine | Studio API Reference - FMOD_STUDIO_EVENT_CALLBACK_STOPPED and restarting the event instance from there? We have scripting example implementing a callback here: Unity Integration | Scripting Examples - Programmer Sounds.

Hope this helps