Event not stopping... another one

Hi

I’m sure I’m being a numpty but I can’t figure out why this isn’t working. I’m starting an event in a start method and then stopping the same event in the same script but it’s not working. If I put in an else it just tells me the stop method wasn’t working. If I use an FMOD emitter (as in the image) it works but I probably need to call this separately and not via game objects. The script has the non-functional bits commented out. Thanks J


script

OK I very much feel that I should have a better handle on handles :rofl:
If someone can take pity and explain this to me it’d be very helpful.
So if I start the music in the Start method of the “MusicManager” it’ll have an invalid handle when I call it from the animation event via this UnityEvent trigger script. If I instead add an OnEnable method in that script the logic works? So does an event always have to be called from the same object?

Hi,

I am a bit confused, Using your script I was able to play the event from the start() function. I would suggest adding some error checking in order to find where it is failing:

private void StudyMusic()
{
    studyMusic = FMODUnity.RuntimeManager.CreateInstance("event:/Music/Level 01");
    if (studyMusic.isValid())
    {
        FMOD.RESULT result = studyMusic.start();
        if (result != FMOD.RESULT.OK)
        {
            Debug.Log(result.ToString());
        }
    }
}

Using the isValid() (FMOD Engine | Studio API reference - EventInstance) will let us know if the CreateInstance() function failed. Next is FMOD.RESULT (FMOD Engine | Core API Reference - FMOD_RESULT) is returned from most FMOD functions and provides more information about why an FMOD Function may have failed.

It seems if the StudyMusic() function is failing there may be an issue with the path passed to the CreateInstance() function.

Not necessarily, it should be possible. What is the object triggering the MusicManager in this image?

Thanks and sorry for my late reply. This was a game jam project and somewhere along the line, the FMOD folder got moved around in the Unity project. I went back and had a look and I can only think that this is the reason for the weird behaviour.

1 Like

Hi,

Thank you for sharing the solution. Hope the game jam went well!