ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.2k stars 152 forks source link

Occlusion only ever occurs from camera, not from where my AudioListener is. #288

Closed RebeccaBieleskiWeta closed 7 months ago

RebeccaBieleskiWeta commented 7 months ago

System Information Please provide the following information about your system:

Issue Description This might just be a problem from how I've set it up, but I'm using SteamAudio to drive our occlusion. When the audiolistener is on the camera, my ambience source is correctly occluded via some SteamAudio Geometry. However, when the audiolistener is on our character, the ambience source is never occluded.

Steps To Reproduce Steps to reproduce the behavior:

  1. Attach AudioListener to Main Camera, notice that it correctly occludes when I put SteamAudio Geometry between the camera and the audio source.
  2. Attach AudioListener to the character, noice that it never occludes the audio source, including when I put SteamAudioGeometry between the character and the source.
achandak commented 7 months ago

@RebeccaBieleskiWeta - Is there a small project you can share with your issues?

We are not able to repro this on our end. The only suggestion I have is to visualize the position of the AudioListener and make sure the position matches your expectation and is occlusion output. Unity probably complains if you have multiple AudioListener so I am ruling that out as an issue.

RebeccaBieleskiWeta commented 7 months ago

Hi there! Thanks for the quick reply.

I can put together an example, I can't show in our project for NDA reasons. I've checked and ensured the audiolistener is where it's meant to be. The test rock music I'm testing with is perfectly occluded when it's on the camera. When it's on our character (I should say it's a third-person game), it just doesn't occlude.

achandak commented 7 months ago

Thanks. If you are able to put together a standalone repro, I can take a look.

RebeccaBieleskiWeta commented 7 months ago

Sure thing! I think this likely be something with how I've set it up in my project, some setting I've not understood. I'll make a new repo and project, replicate it and then link that project here. Edit: I recall, last time I was looking at SteamAudio to see how it would work with our project, the version I installed there came with a test example scene?

RebeccaBieleskiWeta commented 7 months ago

Alright, so I build a basic Unity project, implemented SteamAudio, and occlusion was working perfectly there. Attached to the character, only occluded when raytrace from source to listener is blocked. Within our own project, I've only been able to get the occlusion to work in 2 of two objects I have within my test scene, and only via sticking the source directly into the asset's wall. I'm looking at a way to extract the details from our project without breaking NDA.

RebeccaBieleskiWeta commented 7 months ago

Hi @achandak, I found the cause of the problem. Within our game, the Player was being instantiated after the Steam Audio Manager was being created, meaning that line 46 in UnityAudioEngineState.cs would blindly search our scene with "var audioListener = GameObject.FindObjectOfType();", find the deactivated audiolistener on the camera, and attach to that one.

In order to get it to work with out (although we will need to do some changes to ensure it is grabbing the correct audiolistener on our character), we run NotifyAudioListenerChanged() in SteamAudioManager once our Player has been instantiated.

achandak commented 7 months ago

Ah! Well done. We will add some notes in our documentation, as this might be reasonably common use case.