Losing reference of EventInstance

I have a grenade that needs a hissing sound effect and I’m using an EventInstance to hold it. I create and start the instance when I start aiming. When I go from aiming to throwing the grenade, I need to pass reference to the EventInstance to a new Grenade instance using the old Grenade instance.

public class Grenade : MonoBehaviour
{
    public EventInstance TimerSoundInstance;

    public void Init(GrenadeData data, float timeLeft, Grenade grenade)
    {
        if (grenade)
        {
            TimerSoundInstance = grenade.TimerSoundInstance;
        }
        else
        {
            TimerSoundInstance = AudioManager.Instance.CreateEventInstance(Data.TimerSound);
            TimerSoundInstance.start();
        }
    }
}

I’m storing the references in an AudioManager. When I go to remove the EventInstance from the list, stop it, and release it I see that it’s not in the list and stopping/releasing doesn’t stop the sound. If I debug, I can see that the original Grenade’s EventInstance handle is 2xxxxxx while after I pass it to the new grenade its 0. The EventInstance in the list has the 2xxxxxx handle and the EventInstance passed to StopEventInstance has a handle of 0.

public class AudioManager : SingletonManager<AudioManager>
{
    public List<EventInstance> ActiveEventInstances = new List<EventInstance>();

    public EventInstance CreateEventInstance(EventReference eventReference)
    {
        EventInstance eventInstance = RuntimeManager.CreateInstance(eventReference);
        ActiveEventInstances.Add(eventInstance);
        return eventInstance;
    }

    public void StopEventInstance(EventInstance eventInstance)
    {
        Debug.Log(ActiveEventInstances.Contains(eventInstance)); // returns false
        ActiveEventInstances.Remove(eventInstance);
        eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
        eventInstance.release();
    }
}

Is this a bug or am I handling the EventInstance reference incorrectly? Thanks!

Hi,

I was not able to recreate the issue with my own code. Would it be possible to have the full code or the project uploaded to your profile to test on my end?

Turns out it was unrelated to FMOD. I wasn’t passing something I should’ve when I thought I was. You can mark as resolved/false alarm. Thanks!

1 Like