Hi Guys,
I’m doing this code to set a parameter in unity:
FMODUnity.StudioEventEmitter musicEvent;
var target = GameObject.Find(“MyGameObject”);
musicEvent = target.GetComponent<FMODUnity.StudioEventEmitter>();
musicEvent.SetParameter (“War”, 1.0f);
And it’s working well…
What I want is to retrieve the value of this parameter later on.
For example:
if (MyParameter ==1) {
MyCode();
} else {
MyOtherCode();
}
Something like:
FMOD.Studio.ParameterInstance myParameter;
myParameter = musicEvent.GetParameter (“War”);
What’s the best way to do this ??
Thanks
berli
November 2, 2016, 5:30am
2
float x = 1f;
musicEvent.SetParameter (“War”, x);
x is the value that you change, so use x.
float x = 1f;
musicEvent.SetParameter (“War”, x);
x is the value that you change, so use x.
What I wanted was to avoid using a var just for that. but thanks anyway
You are basically on the money.
Create an event.
Create a parameter instance.
You will need to refer to the parameter by name/string.
Then you can call myParameter.setValue or getValue to change the parameter on the fly. Unfortunately the get function of ParameterInstance doesn’t return a value but outputs it to a given variable.
musicEvent = target.GetComponent<FMODUnity.StudioEventEmitter>();
FMOD.Studio.ParameterInstance myParameter;
myParameter = musicEvent.GetParameter (“War”);
myParameter.getValue(out float);
myParameter.setValue(float);
You are basically on the money.
Create an event.
Create a parameter instance.
You will need to refer to the parameter by name/string.
Then you can call myParameter.setValue or getValue to change the parameter on the fly. Unfortunately the get function of ParameterInstance doesn’t return a value but outputs it to a given variable.
musicEvent = target.GetComponent<FMODUnity.StudioEventEmitter>();
FMOD.Studio.ParameterInstance myParameter;
myParameter = musicEvent.GetParameter (“War”);
myParameter.getValue(out float);
myParameter.setValue(float);
Hey Cameron, thanks for your reply.
The problem is that GetParameter is not a method of the StudioEventEmitter Object. It’s a method of the EventInstance object.
Sorry, the StudioEventEmitter does have Params which returns an array of FMODUnity.ParamRef you can use the same as a ParameterInstance.
For example:
for (int i = 0; i < emitter.Params.Length; i++)
{
if (emitter.Params[i].Name == "ParamterName")
{
param = emitter.Params[i];
}
}
Debug.Log(param.Value);
param.Value += 0.1f;