Changing Fmod Parameter in Unity for Adaptive Audio

Hello!

So I’m trying to make an adaptive music section in my game, in a maze, where the farther the character goes in the maze the different sections of music play. I cannot figure out what I need to do for the life of me to get it to work.

I started with a Scott’s Game Sounds video:
Scott’s Game Sounds Method

I was following it very well and understanding everything up until 16:48, where he implements it through his own script. As far as I could tell, it’s some form of event trigger . I played around with the built in Unity one, but it didn’t play for me, even trying all the parameter types.

I tried that method on a cube/wall thing that is triggered when you pass through it. Then I tried using individual triggers, like the first cube you pass through changes the parameter to 1, and then the second wall turns off the first music and changes the parameter to 2. Moving between different triggers, the first one wouldn’t end when the second one started, I’m guessing because it’s technically playing the music two different times, and I just turned 1 off when 2 started. But I don’t understand how to do it with just one big trigger.

I kept this script from the first video to see if it would help:

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 void Progress(float ProgressLevel)
    {
        Music.setParameterByName("Progress", ProgressLevel);
    }
}

But I don’t understand, similarly, how to change the parameter seamlessly on a single script five different times (there are 5 locations).

Finally I found three videos(the link is one of them).

They are exactly what I need to do, just change the parameter in different area, but idk where to even start since all the other methods didn’t work, and one video offered a link where they learned it and the link was outdated but a little helpful where I made this script:

private static FMOD.Studio.EventInstance Music;


    // Start is called before the first frame update
    void Start()
    {
        Music = FMODUnity.RuntimeManager.CreateInstance("event:/Music/ParameterBasedMusic");





        //Music.release();
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Intro")
        {
            Music.start();
            Music.setParameterByName("Progress", 0f);

        }

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

        }

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

        }

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

        }
    }

But nothing happened so I tried a different approach, putting it on the triggers instead of the player character:

 private static FMOD.Studio.EventInstance Music;


    // Start is called before the first frame update
    void Start()
    {
        Music = FMODUnity.RuntimeManager.CreateInstance("event:/Music/ParameterBasedMusic");





        //Music.release();
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Body")
        {
            Music.start();
            Music.setParameterByName("Progress", 0f);

        }
    }

All the scripts of a similar variety, just any after the first trigger didn’t have Music.start(). When I do that it plays the first time, but does not transition to any other regions.

So that’s everything I tried, I’m not sure where to go next. Thank you for your time, sorry for the long post.

Hi,

To answer this question:

But I don’t understand, similarly, how to change the parameter seamlessly on a single script five different times (there are 5 locations).

Using the Progress(float ProgressLevel) function. It allows the parameter on your Music eventInstance to be changed where ever this function is being called. All you would need to do to call that function is FMODMusic.Progress() and then you could change the parameter of your instance. However, if there is a problem with FMODMusic e.g. not being initialized in your scene, this could cause errors when calling this function. It would be a good idea to add some sort of error checking, either in the FMODMusic class itself or when you use the Progress() function.

I ran your code and it worked well for me, here are a few things you can try to resolve the issue:

A useful tool to use after any FMOD function call is the FMOD.RESULT variable. It will let you know if the function ran successfully or if there was an error. In your example it would be set up like this:

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 the function Music.setParameterByName() ran successfully, the corresponding Debug.Log() will get called, if there was an error we will know exactly which function call it happened on and what type of FMOD error it is. Calling Debug.Log() on both outcomes of the function call will let us know if our program is reaching this code or not, if neither is ever called then we know there is a deeper issue.

Another option to try:
There are two things to check in Unity. That both the Player and Intro objects have a Collider set to Trigger
image
And that they have a RigidBody so that the Colliders are triggering properly.

Hope this helps!

Thank you very much! This worked for me.

1 Like