# FADING, TIMELINES AND PARAMETERS -- How to fade between a few different events all with different loop times -- and to random points?

**URL:** <https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [August 11, 2023, 11:12pm UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531 "2023-08-11T23:12:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![themojius](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/themojius/32/5389_2.png) [@themojius](https://qa.fmod.com/u/themojius)\
**Post date:** [August 11, 2023, 11:12pm UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/1 "2023-08-11T23:12:16Z")

</div>

Hi,

I want to know how to use FMOD Studio for a pretty particular use case.

I’m trying to make a game with 9 different “dimension” settings. Each dimension has its own timeline-based event, a collection of looping sounds, sometimes with scatter instruments thrown in for good measure.

The dimensions are : -4, -3, -2, -1, 0, 1, 2, 3, 4.  
The player can shift from one event to the other, but in increments of 1 or -1. So, a player can go from -4 to -3, or 1 to 0, for instance, but no less than -4 and no greater than 4. Just to give you an idea of the game logic.

What I _really_ want to know is: How would I model this in FMOD? I can’t exactly do this like many people make adaptive music, since my “dimension” settings are discrete, not continuous. And I have no idea how to fade in or out when stopping one event and playing another. Hopefully I’d like the solution to take place in one event, even if it requires sub-events.

Please let me know what I can do to make this work.

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [August 14, 2023, 4:31am UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/2 "2023-08-14T04:31:16Z")

</div>

It sounds like you could make an event containing a discrete or continuous user parameter named “dimension,” create one referenced event instrument for each of your existing dimension events and lay those instruments out along that parameter, and then place an AHDSR modulator on each event instrument’s volume to ensure they crossfade when the value of the “dimension” parameter changes.

---

<div class="post-metadata">

**Author:** ![themojius](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/themojius/32/5389_2.png) [@themojius](https://qa.fmod.com/u/themojius)\
**Post date:** [August 14, 2023, 10:29pm UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/3 "2023-08-14T22:29:30Z")

</div>

That is what I am doing – and that would be all well and good, but even with AHDSR modules on all my sub-events and the master events with big release times, I get absolutely no release time in-game.

Here’s my code:

```auto
  dimensionSound.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

  targetPolarity = stateObject.polarity + delta;

  dimensionSound.setParameterByName("Polarity", targetPolarity);

  dimensionSound.start();

```

And here’s how it sounds in-game.

[https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/d9aae3242dc1d99dca6c2e2a9bedb76f7c538c81.mp4](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/d9aae3242dc1d99dca6c2e2a9bedb76f7c538c81.mp4)

Whereas, if I start the sound from the `Start()` function and change it so the above code only sets the FMOD parameter, no sound plays at all.

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [August 15, 2023, 3:48am UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/4 "2023-08-15T03:48:03Z")

</div>

> [@themojius](#):
>
> Here’s my code:

If you are stopping the event, it is entirely expected that the AHDSR modulators on the instruments aren’t triggered; as described [in our documentation on this topic](https://fmod.com/docs/2.02/studio/troubleshooting.html#ahdsr-modulators-arent-playing-out-their-releases), stopping an event does not untrigger any of the instruments in that event under normal circumstances.

> [@themojius](#):
>
> Whereas, if I start the sound from the `Start()` function and change it so the above code only sets the FMOD parameter, no sound plays at all.

That seems strange, especially as it produces sound when you stop and start the event in the example you gave above.

Is the parameter’s “Hold value during playback” checkbox checked in the edit parameter window? If so, uncheck it. That property prevents the parameter’s value from changing while the event is playing - which is useful in some circumstances, but not in this one.

Otherwise, is the event’s persistent property in the macro controls set to “on?” If not, it may be reaching a natural end and stopping between shifts, and setting it to be persistent should prevent this.

---

<div class="post-metadata">

**Author:** ![themojius](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/themojius/32/5389_2.png) [@themojius](https://qa.fmod.com/u/themojius)\
**Post date:** [August 15, 2023, 11:45pm UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/5 "2023-08-15T23:45:30Z")

</div>

playing the sound once and shifting it – setting them all to “persistent”, and the “hold value during playback” was unchecked – works.

Thank you. Although I am curious as to why the sounds have what sounds like 100ms of lag before playing…

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [August 16, 2023, 5:00am UTC](https://qa.fmod.com/t/fading-timelines-and-parameters-how-to-fade-between-a-few-different-events-all-with-different-loop-times-and-to-random-points/20531/6 "2023-08-16T05:00:07Z")

</div>

I’m glad to hear you were able to get it working.

> [@themojius](#):
>
> I am curious as to why the sounds have what sounds like 100ms of lag before playing…

The various causes of latency are covered in more detail in [this thread](https://qa.fmod.com/t/transitions-latency-when-changing-parameter/14383/35), but the short version is that there are some circumstances where it is physically impossible to avoid latency, and changing the value of a parameter in order to change the behavior of an event involves the intersection of multiple such circumstances.
