I have a particular use case whereby the player character instance is destroyed and recreated at runtime based on a different prefab.
The player character is used as the Attenuation Object on the default Studio Listener component in the scene.
Therefore, during the swap, I need to update said reference to the new player character instance.
I cannot determine a way to achieve this directly in the RuntimeManager API - SetListenerLocation() does something slightly different.
Am I missing something, or is this a restriction due to how the Studio engine works?
I can think of two workarounds (nesting and swapping the player character inside a fixed gameobject used as the attenuation reference, or doing similar for the Studio Listener and swapping them out based on preconfigured attenuation objects) but I would rather not.
I’m afraid I don’t fully understand the problem you’re trying to solve.
You say that the player character is used as the attenuation object, but “attenuation object” isn’t a term that appears in our documentation, so I’m not sure what you mean by it.
It sounds like you might be attaching the listener to a mesh in your game’s world. That seems unlikely, though; very few games do it, as it can easily result in event instances being spatialized in ways that players find confusing or counter-intuitive.
Apologies, for the confusion - when I said Attenuation Object on the default Studio Listener component, I was trying my best to use the official terminology
Here’s a screenshot of the Studio Listener component attached to the main camera in my scene, showing the Attentuation Object field:
And this is the corresponding section of the documentation describing the behaviour:
My understanding is an Attenuation Object is required in order to use a panning effect via the Spatialiser on Events, so that FMOD knows what the point of reference is when “listening” to a “positional” sound.
I would like that point of reference to be the player character instance so that as the player moves around the scene, 3D Events sound closer or more distant, and their audio will pan left or right as the player passes them.
This all works fine, but at some point during runtime in my particular situation, the player character instance is destroyed and replaced witha new one. This is by design, but it does mean the Attenuation Object field on the Studio Listener component loses the reference because it has become null.
I would thus like to update that reference to point at the new player character instance – by script at runtime – but cannot see a straightforward way to do this in the API.
Have I totally misunderstood how to use this component?
Is it enough to have a Studio Listener on the camera as is in my screenshot, without a reference?
Ah! My apologies. I should have thought to check our Unity documentation, as well as the FMOD Studio and FMOD Engine documentation.
I’ve checked with our Unity integration team, and it seems that the reason this isn’t working is that StudioListener.attenuationObject is private. You’ll have to change it from private to public on line 10 of StudioListener.cs. Once you’ve done that, you should be able to set it at run time with a script.
The listener’s position is used for panning sounds, but the attenuation object is used for attenuating them based on distance. If there’s no attenuation object set, the listener’s position is used for attenuating sounds based on distance.
Most games attach the listener to the camera and don’t need a separate attenuation object, since having sounds pan and attenuate based on the position of the camera is normal and intuitive enough that players accept it without question. However, in games where it’s important that the player’s ability to hear in-game sounds depends on their avatar’s distance from the emitter rather than the camera’s distance from that emitter, setting that avatar to be the attenuation object makes sense.