11. Scripting examples | Programmer Sounds - suggestion to improve Scripting example

In your scripting example of Programmer Sounds, would you consider adding an example on how to pass the sound key when the sound is stopped?

Since you cannot Invoke a event, ie: public static event Action<string> OnSoundStopped; from inside the AOT MonoPInvokeCallback. How would you suggest we pass this info to any other scripts that need it?

    OnSoundStopped?.Invoke(key); // Crashes unity

I have not been able to reproduce any issues accessing user data from an event instance during an EVENT_CALLBACK_TYPE.SOUND_STOPPED callback, and I am finding key has a valid value for me in the Programmer Sounds example.

I do not know what OnSoundStopped is, but it is not an FMOD API method so I have no way of knowing why it is crashing. Is this a function you have created? If so, can you please share a code snippet of it?

Thanks for the reply, sorry if I was not clear. I was just wondering if you had any recommendations on how to pass that key from the EVENT_CALLBACK. It would be useful to be able to subscribe to a OnSoundStopped event in order to be notified when the programmer sound is stopped.

The Unity crash does not have anything to do with FMOD, it should be related to the unmanaged native callback into the managed static function.

For now I made it work by storing the key in a private variable, and then passing it when the playback state changes. I do this by calling eventInstance.getPlaybackState(out _playbackState) every frame in Update() and using that to Invoke my event Action OnSoundStopped.

I see what you mean now. There are various options to defer a call until outside of the callback; I agree storing the string value and querying EventInstance.getPlaybackState is a good option in your case. If you wanted a little more versatility and to be able to respond do different callback types then maybe pushing to a command queue and executing in Update would work well.
I have passed your suggestion onto the Dev team to see if we can improve our Programmer Sounds example to support Actions- thanks for the suggestion!