How to load 2 sounds on 1 Unity object

Simple question I know but I can’t work out how to get two sounds working simultaneously on one object. I have a car and want to trigger both an engine note and a transmission whine using parameters to control the sound. Here’s the code as it is:

    public string engineSnd =       "event:/snd_Engine1";
    public string transmissionSnd = "event:/transmissionWhine";
    FMOD.Studio.EventInstance engineEv;
    FMOD.Studio.EventInstance transmissionEv;

    private void Start()
        engineEv = FMODUnity.RuntimeManager.CreateInstance(engineSnd);
        transmissionEv = FMODUnity.RuntimeManager.CreateInstance(transmissionSnd);

    public void playSound()
        engineEv.setParameterByName("RPM", RPM);
        transmissionEv.setParameterByName("carSpeed", carSpeed);

It’s playing the engine but not transmission. Am I doing it wrong?

A number of things could be causing the transmission whine event to not be audible. Your code seems fine, so it’s difficult for me to tell what the issue is without more context. Are you receiving any warnings related to bank loading or the transmission whine event? I would also recommend doing the following and seeing what the results are:

  • Encapsulate your FMOD calls with Debug.Log - i.e. Debug.Log(transmissionEv.start()), Debug.Log(transmissionEv.setParameterByName("carSpeed", carSpeed)); - to check whether any of them return anything other than FMOD.RESULT.OK
  • Use transmissionEv.isValid() to check that the handle of the EventInstance is valid
  • Use transmissionEv.getPlaybackState() to check the playback state of the event

The issue could also be a design-time problem in FMOD Studio - does the transmission whine event play fine in Studio when the parameter is set to the value you’re setting it to in code? Do you have any effects or settings that could be causing it to not output any signal to the master channel? For example:

  • A spatializer that causes the event to be inaudible when set to the 3D position relative to the listener it is in Unity
  • Lack of a Resonance Audio Source, if you’re using the Resonance Audio Listener
  • If you’re creating multiple instances of this event, a low max instance limit combined with the “none” stealing mode

Thanks so much for getting back, really useful help. I worked out that it was my 3d sound not working.

I use cinemachine cameras which are about 100 units above the track (top down game). I tried turning the max distance right up but didn’t hear anything. I have the FMOD listener on the main camera and not cinemachine, could that affect things?

Here is a cinemachine camera setting if that is of use:

It shouldn’t affect things. For the purpose of spatializing your audio, the FMOD Studio Listener component’s 3D attributes will match the transform position of whatever GameObject it’s attached to - the position of your cinemachine camera shouldn’t matter.

That said, if distance between the listener attached to the camera and event is a concern, you can set an “Attenuation Object” in the Studio Listener to, in effect, override using the parent transform position, and instead use the transform position of a different object - for example, an empty GameObject that is a child of the camera, and is significantly closer to your 3D event.

That’s great, thank you. Last question, should I use an emitter for these instances or am I OK as I am? I’ll be adding a lot more sound effects to the car so would like to go about it the optimum way!

The Studio Event Emitter component is designed to be both a simple, relatively code-free method to interact with events, and to serve as an example of how to interact directly with the Studio API with code. A primary limitation of the Emitter is that it can only handle a single event per component - given that you’re planning to play a lot more sound effects, and since you already seem somewhat comfortable with the Studio API, you’d probably find it easier to use your own code.

1 Like