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?
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).
What is FMODAsset in this context? Another script where you kept the EventReference?
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.