Answered
-1
0

I’m trying to do a simple FMOD and Unity 5 Integration test using Box Colliders set to Is Trigger to play a music track and then interact with the Event Parameter in FMOD.

I have two Colliders, my goal is to have the first start the music playing (working) and when the player hits the second collider keep the music playing and send a new value to the Event Parameter in FMOD called “LevelIntensity”.
N.B. The FMOD event is named “Music”.

The first collider is tagged in Unity with the tag “mTrigger”, the second is tagged “iTrigger”.

So far the music trigger is working fine and I am interacting with both colliders (picking them up), and the FMOD event functions properly in Unity (ie, plays and responds correctly to parameter changes in Inspector) so I’m pretty sure all is working except for sending a new parameter value to FMOD.

Here is my code:

The commented-out lines (30,31) are from a debug I found for an error about the Instance returning a null result.

Can anyone help? If you need any more clarification I will not be surprised 😉 I’m a sound designer trying to put my toes into the programming world so as to have a better understanding of the game audio process.

using UnityEngine;
using System.Collections;

public class FMODMusicWorking : MonoBehaviour {

private FMOD.Studio.ParameterInstance levelIntensity; 
private FMOD.Studio.EventInstance iTrigger;


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "mTrigger") {
        other.gameObject.SetActive (false);
        FMOD_StudioSystem.instance.PlayOneShot ("event:/Music", new Vector3 (0, 0, 0));
    }
    if (other.gameObject.tag == "iTrigger") {
        other.gameObject.SetActive (false);
        FMOD_StudioSystem.instance.GetEvent("event:/Music");

        if (iTrigger.getParameter("LevelIntensity", out levelIntensity) != FMOD.RESULT.OK){
            //Debug.LogError ("levelIntensity parameter not found on iTrigger event");
            //return;

        }
        levelIntensity.setValue (51f);
    }
}

}

  • You must to post comments
Best Answer
1
0

I managed to solve this for anyone who’s interested. Updated code below:

using UnityEngine;

using System.Collections;
using FMOD.Studio;

public class FMODMusicWorking : MonoBehaviour {

FMOD.Studio.EventInstance iTrigger;
FMOD.Studio.ParameterInstance musicIntensity; 

void Start () {
iTrigger = FMOD_StudioSystem.instance.GetEvent("event:/Music");

}


void Update () {

}
void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "mTrigger") {
        other.gameObject.SetActive (false);
        iTrigger = FMOD_StudioSystem.instance.GetEvent("event:/Music");
        iTrigger.start();

    }
    if (other.gameObject.tag == "iTrigger") {
        other.gameObject.SetActive (false);
        iTrigger.getParameter ("LevelIntensity", out musicIntensity);
        musicIntensity.setValue(51f);

    }
}

}

  • You must to post comments
1
0

I managed to solve this for anyone who’s interested. Updated code below:

using UnityEngine;

using System.Collections;
using FMOD.Studio;

public class FMODMusicWorking : MonoBehaviour {

FMOD.Studio.EventInstance iTrigger;
FMOD.Studio.ParameterInstance musicIntensity; 

void Start () {
iTrigger = FMOD_StudioSystem.instance.GetEvent("event:/Music");

}


void Update () {

}
void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "mTrigger") {
        other.gameObject.SetActive (false);
        iTrigger = FMOD_StudioSystem.instance.GetEvent("event:/Music");
        iTrigger.start();

    }
    if (other.gameObject.tag == "iTrigger") {
        other.gameObject.SetActive (false);
        iTrigger.getParameter ("LevelIntensity", out musicIntensity);
        musicIntensity.setValue(51f);

    }
}

}

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.