# SetTimelinePosition not working?

**URL:** <https://qa.fmod.com/t/settimelineposition-not-working/20961>\
**Category:** Unity\
**Created:** [December 6, 2023, 2:38pm UTC](https://qa.fmod.com/t/settimelineposition-not-working/20961 "2023-12-06T14:38:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sirevanac](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/sirevanac/32/480_2.png) [@Sirevanac](https://qa.fmod.com/u/Sirevanac)\
**Post date:** [December 6, 2023, 2:38pm UTC](https://qa.fmod.com/t/settimelineposition-not-working/20961/1 "2023-12-06T14:38:24Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [December 10, 2023, 11:40pm UTC](https://qa.fmod.com/t/settimelineposition-not-working/20961/2 "2023-12-10T23:40:01Z")

</div>

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](https://fmod.com/docs/2.02/api/core-api-common.html#fmod_result) which can provide more information when debugging FMOD functions.

Please try swapping the order of the functions to:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Sirevanac](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/sirevanac/32/480_2.png) [@Sirevanac](https://qa.fmod.com/u/Sirevanac)\
**Post date:** [December 26, 2023, 7:59pm UTC](https://qa.fmod.com/t/settimelineposition-not-working/20961/3 "2023-12-26T19:59:49Z")

</div>

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!
