setParameterValue

Hello,

I’m attempting to change an event parameter from script using setParameterValue.

So far I can confirm that the script is calling, but the parameter does not appear to be changing (the expected change to the event is not occurring). I’m not producing any FMOD_DEBUG error messages.

Am I using the correct method for changing an event parameter? Is there a way for me to better debug the script call is being received correctly?

Thank you for responding, and forgive my ignorance, I don’t claim to be a well-versed programmer.

When you say remove the FMOD_StudioEvent, are you referring to FMOD.Studio.EventInstance Music;
or Music = FMOD_StudioSystem.instance.GetEvent ("event:/BattleMusic");
?

I thought you were referring to Music = FMOD_StudioSystem.instance.GetEvent ("event: /BattleMusic");
but then Music.start(); returns null in the Start() function. So I tried removing FMOD.Studio.EventInstance Music; but then I am told that “Music” does not exist in its current context with the line Music = FMOD_StudioSystem.instance.GetEvent ("event: /BattleMusic");
.

Could you be more specific? I thought there already was a Start() method, or is that just a regular function? Now that you’ve pointed it out to me, I understand that I’m not referencing the FMOD Emitter, and I appreciate that.

So how do I reference it instead of creating a new instance? Or should I not use the Emitter and just create a new instance? I did add Music.start() but I am still unclear on how to define my Music variable so that it is referencing the FMOD_Studio Event Emitter.

Thank you again, I appreciate your patience greatly.

Hey! I got it working! Thank you so much! I didn’t have to delete any line though, I just added Music.start(); in between “Music = FMOD_Studio.instance.GetEvent(“event:/BattleMusic”);” and “Music.getParameter(“Combat”, out combatVal);” and it WORKED! I also had to make sure “Start Event on Awake” was unchecked on the FMOD_Studio Event Emitter Component.

Thank you so much!

Hi! I’m having this exact issue in that I am trying to change a parameter set in FMOD Studio from within Unity. When I’m in FMOD Studio, I have a series of loop regions and transition regions set up and altering the parameter while the event is playing produces the desired event behavior. To provide as much info as I can, here’s a screenshot of my FMOD Studio event:

http://i.imgur.com/3jxhvFj.png

I attached the FMOD_Studio Event Emitter script to an Empty Game Object and the only other component the object has besides a Transform is the script I’m trying to use to control the Combat parameter of my event, named AMBController.

It’s a very simple script:

using UnityEngine;
using System.Collections;

public class AMBController : MonoBehaviour {

	public bool combat;

	FMOD.Studio.EventInstance Music;
	FMOD.Studio.ParameterInstance combatVal;

	// Use this for initialization
	void Start () {
		combat = false;

		Music = FMOD_StudioSystem.instance.GetEvent ("event:/BattleMusic");
		Music.getParameter("Combat", out combatVal);
	}

	// Update is called once per frame
	void Update () {
		bool toggle = Input.GetKeyUp (KeyCode.Space);

		if (toggle) {
			if (!combat) {
				combat = true;
				combatVal.setValue(0.9f);
			}
			else if (combat) {
				combat = false;
				combatVal.setValue(0.1f);
			}
		}
	}
}

My “To Combat_On” transition region is set to trigger whenever the Combat parameter is between 0.58 and 1.0; the “To Combat_End” transition region is set to trigger when the Combat parameter is between 0.0 and 0.47, so using 0.1f and 0.9f are relatively arbitrary values for triggering the transition regions in my BattleMusic event.

When I begin playing the scene, I hear the BattleMusic event playing, but when I hit the space key, the event does not transition at all to the Combat_On marker in my FMOD event, even though I can see that the public bool combat is toggling on and off in Unity’s Inspector window.

Please help? I’m not getting any errors in Unity’s console at all and I’m quite stumped.

-Mike Patterson

Hi MikePatterson,

I believe you missed one little thing.
When you assign the event to the Music field, you’re not referencing the FMOD Emitter, but you’re creating a new instance of that sound.
To fix this, remove the FMOD_STudioEvent, create a Start method on your AMBController class, and call Music.start().

The way I do is something like this:

public FMODAsset SoundAsset; //Define this at the editor

EventInstance soundInstance;
ParameterInstance paramInstance;

public void CreateSoundInstance()
{
      soundInstance = FMOD_StudioSystem.instance.getEvent(SoundAsset);
      soundInstance.getParameter ("MyParam", out paramInstance);
}

public void SetValue(float newValue)
{
      paramInstance.setValue (newValue);
}

Have you tested adjusting the parameter at the FMOD Studio? Did it work there?

Thank you so much, dnishimura!

I was forgetting to prefix my “paramInstance” argument with “out” inside getParameter.