Set 3D attributes Unity script syntax and correct use

Hi,

I’m doing a little project at home to try and learn how to use unity and fmod. I’m having some difficulty finding a working example of what i’d like to do.

Basically i want to simply trigger a sound from a game object which exists in my level.

So far i’ve not really found anything that seems to be up to date, so i thought i’d ask on here :slight_smile: I’m running unity 5.4 and fmod studio 1.08.09

I have a script i got from unity asset manager which handles the timing of playing the foot step samples fine, along with camera behaviour. It had some foot step audio triggers in there already which worked ok but it was just using the unity audio engine but i would like to learn how to use the fmod engine :slight_smile:

The script i got essentially added an audio source to the fps controller and used that to define the world position.

It seems that you can’t really use studio event emitters in the same way. As falloff attenuation etc is handled within the event in fmod, it’s not as nessercary within fmod anyway.

My play sound script section for fmod is quite simple, as follows:

FSev = FMODUnity.RuntimeManager.CreateInstance(Footsteps);
        FSev.start();

At the top all i’m doing is declaring the event and there is nothing about world position.

When i run the game i get a message along the lines of you need to set 3d attributes as your sound is playing at world 0.

I’ve had a good old guess at what the syntax might be but i’m basically not sure what arguments i need, any declarations of objects from unity i need, how that would all get tied together in a unity script.

Any help anyone can provide would be greatly appreciated.

Thanks,
Ben

If your footstep event is continuous I would use

FMODUnity.RuntimeManager.AttachInstanceToGameObject(FSev,  GetComponent<Transform>(), GetComponent<Rigidbody>());

this example also has what you’re after http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_basic.html

1 Like

hi! thanks for that it sent me down the correct path. :slight_smile: i’ve ended up using FSev.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject, playerPos)); to set the 3d position each time a foot step is played. Which seems to work. Not sure if it’s best practise or not but setting it each time the sound is played is probably the most effecient solution?

to further explain where i was going wrong in case anyone else gets stuck where i was. I didn’t understand how you used (gameObject, TheObjectNameYouDeclaredIt) so i was thinking i had to replace the word gameObject with the name. I also didn’t understand the use of Rigidbody whateveriwanttocallit; and then the need to use get component so i can then use rigidbody for my purposes.

Thank you, this question has been very helpful to me. I chose to place

FMODUnity.RuntimeManager.AttachInstanceToGameObject(walkEv, GetComponent(), GetComponent());

right after my NameOfEvent.play(); line:

void Update () {
if(Input.GetButtonDown (“Vertical”))
{
walkEv.start();
FMODUnity.RuntimeManager.AttachInstanceToGameObject(walkEv, GetComponent(), GetComponent());
}
if(Input.GetButtonUp (“Vertical”))
{
walkEv.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
}
}

My looping walking sound is now following my main character around when it moves, but I still get the warning message “Instance of Event event:/Walk_Lp found playing at the origin”. Does anybody know why the warning message still pops up? Or can I just ignore it?

If the sound is located at zero of its parent object, you will still get this warning.
It is safe to ignore.