API error when using PlayOneShotAttached - EventInstance::getPlaybackState() returned ERR_INVALID_HANDLE for STUDIO_EVENTINSTANCE

Hi, I am seeing the errors below when playing any sound attached to a Game Object, 2D or 3D. The sounds play fine but they spam these errors in the console.

I’ve reproduced this on FMOD 2.01.11 in a clean Unity project 2019.4.28.f1 with the most basic code possible (below). API Error Logging is enabled.

I noticed this similar post, but I’m not sure if this should have been fixed on 2.01.11 or if it’s a separate issue?

Here’s the error message in full:

[FMOD] EventInstance::getPlaybackState(000000C29BFBE1E8) returned ERR_INVALID_HANDLE for STUDIO_EVENTINSTANCE (0x2006A0).
UnityEngine.Debug:LogError (object)
FMODUnity.RuntimeManager:ERROR_CALLBACK (intptr,FMOD.SYSTEM_CALLBACK_TYPE,intptr,intptr,intptr) (at Assets/Plugins/FMOD/src/Runtime/RuntimeManager.cs:63)
FMOD.Studio.EventInstance:getPlaybackState (FMOD.Studio.PLAYBACK_STATE&) (at Assets/Plugins/FMOD/src/Runtime/wrapper/fmod_studio.cs:1235)
FMODUnity.RuntimeManager:Update () (at Assets/Plugins/FMOD/src/Runtime/RuntimeManager.cs:477)
using FMODUnity;
using UnityEngine;

public class PlaySoundOnAnimationEvent : MonoBehaviour
{
  [EventRef] public string fmodEventPath;

  public void PlayOneShotSound()
  {
    RuntimeManager.PlayOneShotAttached(fmodEventPath, gameObject);
  }
}

I have reproduced the error using your code and it appears that attached instances are still affected by this bug, so RuntimeManager.PlayOneShotAttached will still throw errors when API Error Logging is enabled.
Hopefully we can get a patch out quickly, in the meantime if you urgently need to use attached instances with API Error Logging enabled you can make the following change to “<project_name>/Plugins/FMOD/src/Runtime/RuntimeManager.cs” lines 476-481:
Replace this

FMOD.Studio.PLAYBACK_STATE playbackState = FMOD.Studio.PLAYBACK_STATE.STOPPED;
attachedInstances[i].instance.getPlaybackState(out playbackState);
if (!attachedInstances[i].instance.isValid() || 
   playbackState == FMOD.Studio.PLAYBACK_STATE.STOPPED ||
   attachedInstances[i].transform == null // destroyed game object
   )

With this

FMOD.Studio.PLAYBACK_STATE playbackState = FMOD.Studio.PLAYBACK_STATE.STOPPED;
if(attachedInstances[i].instance.isValid())
   attachedInstances[i].instance.getPlaybackState(out playbackState);
if (playbackState == FMOD.Studio.PLAYBACK_STATE.STOPPED || 
    attachedInstances[i].transform == null // destroyed game object
    )
1 Like

Awesome, thank you so much for the expedient response and codefix @jeff_fmod!