Trouble playing event based on boolean

I’m having all kinds of trouble with something that seems simple, so I think I’m missing something but for the life of me I can’t find what that is.

I have a simple bool, and I’d like to play an event when the bool is set to true. For context, this would be a looping boost/nitro sound for a car when the boost button is held down.

Here’s what I’ve tried:

  • Using SendMessage (“Play”) while true, and SendMessage (“Stop”) while false within a method in Update - this results in no audio or the event clicking and not playing (presumably because it’s trying to play/stop every frame)

  • Using SendMessage (“Play”) while true and removing SendMessage (“Stop”) will allow the sound to play, but it will only play after the button is released, not on press or while it’s being held. Obviously, it just repeats endlessly as well.

The event is a simple Timeline Sheet with a looping region + an Action Sheet with some instruments that play when triggered for a startup sound. It works fine in Studio.

I’ve also tried an alternate route where I just used a Continuous Parameter sheet between 0-1, and automated the volume based on the value (false = 0, true = 1). I did start that event on object start via the Studio Event Emitter component. That worked fine, which is even more confusing as it used the same bool, so I’m not sure why. I want to use the Timeline version so I can call the event when needed, but not have it continually playing in the background, even silently.

For additional context, in Unity I’m using the new input manager, and my button is set to Button, and I’m just checking whether it’s true or false in code. The boost works correctly on my rigidbody (applies a continuous force while pressed), so I’m assuming I’m missing something important regarding how to use Fmod.

Any help is much appreciated.

  1. Quite as you done it in working alternate way: have the event be playing all the time, and use labeled parameter (values false/true) then on parameter sheet placing your instruments/nested event with loop on true, false leaving empty

  2. use bool inside bool, one will be triggering “play” second will be checking “if it was already played”

  3. instead of bool, make it start playing on starting pressing the key, and release it on stopping pressing the key,

1 Like

@Janusz thanks!

Option 2 is the fix I was looking for - I used the isPlaying() method from Fmod and it works great.

Thanks again!

2 Likes