Getting info on whether an event instance start got canceled by Cooldown macro

I have an audio script that works very similarly to StudioEventEmitter oneShot, the flow basically goes like this:

  • Call Play
  • This starts an audio instance1
  • Call play again (really quickly, even same frame possible)
  • Audio instance1 gets all handles released and is just left to finish and play out on its own. Audio instance2 gets created and is started.
  • Audio instance2 is not playing because of Cooldown restrictions
  • Any variable changes now get directed to instance2, so any variable changes get applied to the sound that is not playing.

There are other solutions to this, but the simplest and most elegant one would be for me to create instance2 and try to launch it before dropping all the handles of instance1 and then if instance2 launch is not possible because of Cooldown, retain instance1. But calling start on instance2 returns FMOD.RESULT OK. Is there a way to check for this?

Hi,

Thank you for the detailed explanation.

An option could be assigning a callback to the event instance and making sure that FMOD_STUDIO_EVENT_CALLBACK_STARTED (FMOD engine | Studio API Reference - FMOD_STUDIO_EVENT_CALLBACK_TYPE) is hit before releasing references to instance1? An example of assigning a callback can be found here: Unity Integration | Scripting Examples - Programmer Sounds.

If this does now meet your needs, would it be possible to share the code?

Hmm, thanks! I’ll try it. Although if it’s a callback that happens later and is not instant, this implies that I’ll need to keep an entire queue of instances awaiting the swap (since there can be multiple calls to play a new instance) and that queue will have to clean itself out. But thanks, I’ll give it a go and see how this turns out.

1 Like