# Parameter Based Audio Doesn't Go Backwards

**URL:** <https://qa.fmod.com/t/parameter-based-audio-doesnt-go-backwards/19314>\
**Category:** FMOD Studio\
**Tags:** unity, csharp\
**Created:** [September 24, 2022, 5:57pm UTC](https://qa.fmod.com/t/parameter-based-audio-doesnt-go-backwards/19314 "2022-09-24T17:57:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnGreska](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@JohnGreska](https://qa.fmod.com/u/JohnGreska)\
**Post date:** [September 24, 2022, 5:57pm UTC](https://qa.fmod.com/t/parameter-based-audio-doesnt-go-backwards/19314/1 "2022-09-24T17:57:09Z")

</div>

Hi!

I have in my game a maze, where the music changes based on your progress in the maze. It works pretty well, but it has a few issues. The biggest one being the audio doesn’t change going backwards. Here is the script I’m currently using (I agree, the current naming system I have is horrible).

```auto
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FMODMusic : MonoBehaviour
{
    private static FMOD.Studio.EventInstance Music;
    
    // Start is called before the first frame update
    void Start()
    {
        Music = FMODUnity.RuntimeManager.CreateInstance("event:/Music/ParameterBasedMusic");

        //Music.start()
        //Music.release();
    }

    // Update is called once per frame
    public static void Progress(float ProgressLevel)
    {
        Music.setParameterByName("Progress", ProgressLevel);

    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Intro")
        {
            FMOD.RESULT result;
            result = Music.start();

            if (result == FMOD.RESULT.OK)
                Debug.Log("Successfully started the music");
            else
            {
                Debug.Log("Failed to start the music with the result of " + result);
            }

            result = Music.setParameterByName("Progress", 0f);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Entered First Area");
            else
            {
                Debug.Log("Failed to change Music Progress with the result of " + result);
            }
        }

        if (other.gameObject.tag == "Intro2")
        {
            FMOD.RESULT result;
            result = Music.setParameterByName("Progress", 1f);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Entered Second Area");
            else
            {
                Debug.Log("Failed to change Music Progress with the result of " + result);
            }
 
        }

        if (other.gameObject.tag == "First")
        {
            FMOD.RESULT result;
            result = Music.setParameterByName("Progress", 2f);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Entered Third Area");
            else
            {
                Debug.Log("Failed to change Music Progress with the result of " + result);
            }

        }

        if (other.gameObject.tag == "Second")
        {
            FMOD.RESULT result;
            result = Music.setParameterByName("Progress", 3f);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Entered Fourth Area");
            else
            {
                Debug.Log("Failed to change Music Progress with the result of " + result);
            }

        }

        if (other.gameObject.tag == "Third")
        {
            FMOD.RESULT result;
            result = Music.setParameterByName("Progress", 4f);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Entered Fifth Area");
            else
            {
                Debug.Log("Failed to change Music Progress with the result of " + result);
            }

        }

        if (other.gameObject.tag == "Desert")
        {

            transform.position = new Vector3(83f, 1.5f, -14f);
            FMODUnity.RuntimeManager.PlayOneShot("event:/Portal", transform.position);

            FMOD.RESULT result;
            result = Music.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

            if (result == FMOD.RESULT.OK)
                Debug.Log("Stopped Audio");
            else
            {
                Debug.Log("Failed to stop Music Progress with the result of " + result);
            }

        }
    }

}

```

Basically, if I were to go from section 4 to section 3 in the maze, I would like the music from section 4 to calm back down to the music of section 3. But it doesn’t do that, no matter how far back I go, it continues to play the music of section 4.

I am debugging, and it shows that as it goes backwards, it does pass through the triggers and register the change in parameter. But the audio itself doesn’t change. Here is how I currently have it set up:

[FMOD set up](https://ibb.co/wRqGQT0)

In the progress tab, it goes up and down visually if I play with the parameter slider.

Thanks

---

<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:** [September 27, 2022, 12:16am UTC](https://qa.fmod.com/t/parameter-based-audio-doesnt-go-backwards/19314/2 "2022-09-27T00:16:52Z")

</div>

Hi,

Each transition region can only be set to one destination. So in your example currently section 4 has no way to transition back to section 3. Add another transition region to Section 4 that’s destination is set to 3, then in your code add a `previousSection` variable that keeps track of the last entered area so you know where the player is coming from and set the new parameter accordingly. e.g. transition from section 2 to 3 will change the parameter to 3, while a transition from section 3 to 2 will change it to 5.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/a85d64d291689c0fe45d755d356b4d92f1134c01.png)

Keep in mind that Transition Regions are evaluated top to bottom, if you wish you can use this to set up more complex conditional behaviors.

Hope this helps!
