# Unity - Playing an Fmod Event on an Animation's Keyframe

**URL:** <https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836>\
**Category:** Unity\
**Created:** [February 25, 2015, 12:06pm UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836 "2015-02-25T12:06:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [February 25, 2015, 12:06pm UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836/1 "2015-02-25T12:06:08Z")

</div>

I have Fmod Studio integrated with Unity and I’m now trying to play an Fmod Studio Event on an animation’s keyframe.

On the Animation’s timeline I set a keyframe to enable the following script:

```
using UnityEngine;
using System.Collections;
using FMOD.Studio;

public class AnimationPlayFmodSound : MonoBehaviour {

	void OnEnable () {
		FMOD_StudioSystem.instance.PlayOneShot ("event:/Resources/FX/fx_column_effect", transform.position);		
	}
}

```

I thought it should play only when the script is enabled, but apparently the event plays as soon as I start the game (before the animation occurs). What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![SoundOfSyndrome](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@SoundOfSyndrome](https://qa.fmod.com/u/SoundOfSyndrome)\
**Post date:** [February 25, 2015, 9:18pm UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836/2 "2015-02-25T21:18:00Z")

</div>

This works for me:

```
using UnityEngine;
using System.Collections;

public class SoundEvent : MonoBehaviour {

public FMODAsset A_EventSound;
	
public void PlaySound (FMODAsset A_EventSound) {
		if(A_EventSound != null)
		{
			FMOD_StudioSystem.instance.PlayOneShot(A_EventSound, transform.position);
		}
		else
		{
			Debug.LogError("EventSound is null");
		}
		
	}
}

```

The script is attached to the root of the GameObject (model).

---

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [February 26, 2015, 10:56am UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836/3 "2015-02-26T10:56:21Z")

</div>

> [@](#):
>
> This works for me:
> 
> ```
> using UnityEngine;
> using System.Collections;
> 
> public class SoundEvent : MonoBehaviour {
> 
> public FMODAsset A_EventSound;
> 	
> public void PlaySound (FMODAsset A_EventSound) {
> if(A_EventSound != null)
> {
> FMOD_StudioSystem.instance.PlayOneShot(A_EventSound, transform.position);
> }
> else
> {
> Debug.LogError("EventSound is null");
> }
> 		
> }
> }
> 
> ```
> 
> The script is attached to the root of the GameObject (model).

It works! Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Gmanmondo](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@Gmanmondo](https://qa.fmod.com/u/Gmanmondo)\
**Post date:** [April 3, 2024, 10:05pm UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836/4 "2024-04-03T22:05:09Z")

</div>

What is FMODAsset in this context? Another script where you kept the EventReference?

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [April 8, 2024, 3:20am UTC](https://qa.fmod.com/t/unity-playing-an-fmod-event-on-an-animations-keyframe/11836/5 "2024-04-08T03:20:37Z")

</div>

This thread is extremely old at this point - `FMODAsset` was a class in a now long-deprecated version of the FMOD for Unity plugin that stores a reference to an Event’s path and ID for the purposes of creating instances of that event at runtime. It can be considered a simplified version of, but roughly equivalent to, the `EventReference` class that is used in modern versions of the integration.
