Hi guys,
I’m an audio engineer and been using FMOD for a while now. I’ve recently been coding a bit more, thanks to chatGPT and some basic understanding. I’m trying to write code that can take a local parameter’s information and based on the FMOD paramer, send a animator parameter (trigger) to a connected animator.
For visual reference: I’m creating a band that plays music. The music has certain parts where the drummer plays, other parts where he doesn’t. So I thought if I have a parameter for whether he “isPlaying” and “stopPlaying” which I control with a Command Instrument (who sets the parameter), for every band member in the arrangement.
So I think it works to set the value of the parameter in FMOD with the command instrument. Now, I only need to make a script in Unity that sends those values to a connected animator and trigger an animator state. Can anyone help me deceiver this code and make it work? One problem I already know is that the code is constantly triggering the animator controller trigger. It should do that only once (as it’s a trigger and not a boolean). Now, it’s kind of stuck on “stopPlaying”. I’m using a labeled parameter in FMOD. 0 = stopPlaying. 1 = startPlaying.
using UnityEngine;
using FMODUnity;
public class FMODAnimatorController : MonoBehaviour
{
[SerializeField] private Animator animator;
[SerializeField] private StudioEventEmitter fmodEvent;
[SerializeField] private string stopPlayingParameter;
[SerializeField] private string startPlayingParameter;
[SerializeField] private FMOD.Studio.PARAMETER_ID localFMODParameter;
private void Start()
{
fmodEvent.Play();
Debug.Log("FMOD event has started playing.");
}
private void Update()
{
float localFMODParameterValue;
fmodEvent.EventInstance.getParameterByID(localFMODParameter, out localFMODParameterValue);
Debug.Log("Local FMOD parameter name: " + localFMODParameter);
if (localFMODParameterValue == 0)
{
animator.SetTrigger(stopPlayingParameter);
Debug.Log("Animator trigger for " + stopPlayingParameter + " has been set.");
}
else if (localFMODParameterValue == 1)
{
animator.SetTrigger(startPlayingParameter);
Debug.Log("Animator trigger for " + startPlayingParameter + " has been set.");
}
}
}