# API error when using PlayOneShotAttached - EventInstance::getPlaybackState() returned ERR\_INVALID\_HANDLE for STUDIO\_EVENTINSTANCE

**URL:** <https://qa.fmod.com/t/api-error-when-using-playoneshotattached-eventinstance-getplaybackstate-returned-err-invalid-handle-for-studio-eventinstance/17487>\
**Category:** Unity\
**Created:** [July 28, 2021, 2:36am UTC](https://qa.fmod.com/t/api-error-when-using-playoneshotattached-eventinstance-getplaybackstate-returned-err-invalid-handle-for-studio-eventinstance/17487 "2021-07-28T02:36:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![energytankstudios](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@energytankstudios](https://qa.fmod.com/u/energytankstudios)\
**Post date:** [July 28, 2021, 2:36am UTC](https://qa.fmod.com/t/api-error-when-using-playoneshotattached-eventinstance-getplaybackstate-returned-err-invalid-handle-for-studio-eventinstance/17487/1 "2021-07-28T02:36:46Z")

</div>

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?

> [@I always get "ERR\_INVALID\_HANDLE for CHANNEL (0x7FE0009)" error when trying to play any sound](https://qa.fmod.com/t/i-always-get-err-invalid-handle-for-channel-0x7fe0009-error-when-trying-to-play-any-sound/17372/8):
>
> Thanks for the additonal information, we have come across the API Error Logging bug as well. Both issues have been patched for the next release, which will be available by the end of the month.

Here’s the error message in full:

```auto
[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)

```

```auto
using FMODUnity;
using UnityEngine;

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

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

```

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [July 28, 2021, 11:23pm UTC](https://qa.fmod.com/t/api-error-when-using-playoneshotattached-eventinstance-getplaybackstate-returned-err-invalid-handle-for-studio-eventinstance/17487/2 "2021-07-28T23:23:07Z")

</div>

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

```auto
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

```auto
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
    )

```

---

<div class="post-metadata">

**Author:** ![energytankstudios](https://avatars.discourse-cdn.com/v4/letter/e/8e8cbc/32.png) [@energytankstudios](https://qa.fmod.com/u/energytankstudios)\
**Post date:** [July 29, 2021, 1:29am UTC](https://qa.fmod.com/t/api-error-when-using-playoneshotattached-eventinstance-getplaybackstate-returned-err-invalid-handle-for-studio-eventinstance/17487/3 "2021-07-29T01:29:06Z")

</div>

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