I’m trying to trigger the local labelled parameter Ball Weight to change which Ball Destroy sfx to play per instance of ball.
Here’s the prefabs:
In the following FSM, the Weight variable is retrieved in Get Parent Ball and set as the variable BallWeight within the FSM.
With String Compare, I check value of BallWeight and send it to the corresponding state, which then sets the parameter integer value as ParameterValue.
Finally, I use the ParamaterValue to set the local Ball Weight parameter with a custom script, then call Play() on the attached emitter.
Here’s the script:
using UnityEngine;
using HutongGames.PlayMaker;
using FMODUnity;
using FMOD.Studio;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("FMOD")]
[Tooltip("Sets a local FMOD parameter on a Studio Event Emitter using an FsmVar.")]
public class SetLocalFMODParameter : FsmStateAction
{
[RequiredField]
[Tooltip("GameObject containing the FMOD Studio Event Emitter.")]
public FsmOwnerDefault gameObject;
[RequiredField]
[Tooltip("Name of the FMOD parameter.")]
public FsmString parameterName;
[RequiredField]
[Tooltip("Value to set (Float, Int, or String for labeled parameters).")]
public FsmVar parameterValue;
[Tooltip("Repeat every frame.")]
public bool everyFrame;
private StudioEventEmitter emitter;
private EventInstance eventInstance;
public override void Reset()
{
gameObject = null;
parameterName = "";
parameterValue = new FsmVar();
everyFrame = false;
}
public override void OnEnter()
{
DoSetParameter();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoSetParameter();
}
void DoSetParameter()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
return;
if (emitter == null)
emitter = go.GetComponent<StudioEventEmitter>();
if (emitter == null)
return;
eventInstance = emitter.EventInstance;
switch (parameterValue.Type)
{
case VariableType.Float:
eventInstance.setParameterByName(
parameterName.Value,
parameterValue.floatValue
);
break;
case VariableType.Int:
eventInstance.setParameterByName(
parameterName.Value,
parameterValue.intValue
);
break;
case VariableType.String:
eventInstance.setParameterByNameWithLabel(
parameterName.Value,
parameterValue.stringValue
);
break;
}
}
}
}
I’m aware local parameters can’t be updated before the instance is created, and I‘ve tried triggering Play() and then setting the parameter (with and without a frame delay) but with no luck.
Oh, and for the purposes of testing I’m hard coding the values. Once it’s working, I’ll dynamically set the parameter by the label name. This was my initial setup which didn’t work, so I changed it to use the integer values instead in hopes this would solve the issue.







