SetTimelinePosition not working?

Hi! I’m with Unity and Fmod 2.02.13. Here’s the situation:

It’s a VR game. To go through rooms, the player has to put its hand a “portal charger”. The portal charger has a 2 second charge with a 2 second sfx. If at any point the player takes out the hand of the “portal charger”, the charge up to that point slowly diminishes to 0, but if the player puts the hand again before it reaches 0, the charge continues from the point it was charged on that point.

So the SFX must continue from the charge % of when te player puts the hand again. If the charge of the portal is at 50% and the player places the hand again on it, it has to start at 50% of the sfx.

So I tried this code:

StudioEventEmitter portalSoundActivating; //Sfx is loaded through a EventEmitter
float chargedValue; //I'm leaving out the part where this is being loaded but it works fine
int loadedValue; 

private void OnTriggerEnter(Collider other) {
    if (chargeValue > 0){
             loadedValue = Mathf.FloorToInt(chargedValue * 2000); //ChargedValue goes from 0 to 1 and the sfx lasts 2 seconds, hence the *2000
             portalSoundActivating.EventInstance.setTimelinePosition(loadedValue); 
              portalSoundActivating.Play();
    }
}

I’ve checked through debugging and loadedValue gives a value between 0 and 2000. And double checked that this is not working moving the sfx 1000ms on the timeline and no matter the value of loadedValue, it waited a full second before reproducing. Is there anything wrong that I’m doing?

Edit: Also tried automating the offset as a way around, but it works quite clunky and is not consistent.

Hi,

The issue may be trying to call setTimelinePosition() on the event before it has been created. I would recommend checking the result of the function using FMOD.RESULT which can provide more information when debugging FMOD functions.

Please try swapping the order of the functions to:

FMOD.RESULT result = portalSoundActivating.Play();
if (result != FMOD.RESULT.OK)
{
    Debug.Log(result)
}
result = portalSoundActivating.EventInstance.setTimelinePosition(loadedValue); 
if (result != FMOD.RESULT.OK)
{
    Debug.Log(result)
}

Hope this helps!

Hi Connor! So after some more digging and watching closely what you wrote, I realized that I had to execute the sound first and then assign the timeline! It does not work backwards.

Thanks you very much!

1 Like