ValveSoftware / steam-audio

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

Dynamic objects does not work as expected #298

Closed jordihuertas closed 4 months ago

jordihuertas commented 5 months ago

System Information

Issue Description I have 2 rooms, 1 with a steam audio source (more audio sources playing the same audio so far away, playing the audio at the same time), and between them a dynamic object door.

All the walls and the door have occlusion 100%. So no sound should tresspass.

Then my tests are opening and closing the door from the room without audio. It works great as the player keeps moving. But if I stop moving the player just before the door closes, I keep listening the audio as a reflection.

Example moving the dynamic object transform: https://www.youtube.com/watch?v=CZUDK2PGfXQ Example moving the dynamic object rigidbody: https://www.youtube.com/watch?v=IPP6YmnLHtc

As you can see in the video, the audio keeps playing until the listener transform moves.

EDIT

--

Also tried to reproduce it with 3 rooms and 2 audio sources (middle room is empty). The only thing I get so far is that the dynamic objects only works if the audio source is a new one.

I mean: If I duplicate the RoomA audio source (and disable the original copy) the dynamic object will oclude the sound and the RoomB will not. Then I duplicate the RoomB audio source (and disable the original copy) and the dynamic object will oclude the sound and the roomA will not.

--

Also tested with primitive objects as walls and as dynamic objects.

All is being tested with realtime reflections.

Images attached:

Dynamics objects config (doors): image

Audio sources: image

Steam Audio settings: image

achandak commented 5 months ago

@jordihuertas - I cannot repro the issue on a setup similar to yours. Are you in a position to share a standalone issue? Might be faster to resolve the issue that way. Here is some additional insight:

See SteamAudioDynamicObject.cs (Lines 61-67). We rely on transform.hasChanged to make sure Steam Audio internal geometry structure is updated and that simulation is indeed updated. Is there a special way you might be handling transform for the door?

// Only update the dynamic object if it has actually move this frame if (transform.hasChanged) { mInstancedMesh.UpdateTransform(SteamAudioManager.CurrentScene, transform); SteamAudioManager.ScheduleCommitScene(); transform.hasChanged = false; }

jordihuertas commented 5 months ago

@achandak I do not know what is a standalone issue, could you please explain to me?

There is no any special way, just a transform position. The second video I attached is just pushing a rigidbody with a hinge.

jordihuertas commented 5 months ago

@achandak I think I am a little closer to the problem. Maybe you can reproduce it this way.

2 audio sources playing the same clip from a script. The dynamic object only excludes the last created one. *Only in a while. This is really weird.

achandak commented 5 months ago

Sorry, I meant a standalone project or a small Unity project that reproduces the issue. We tried all obvious things we thought could go wrong.

I will try spawning additional sources.

jordihuertas commented 5 months ago

Yes, I will try to reproduce in a new project. I will feedback you tomorrow.

jordihuertas commented 5 months ago

@achandak here it is. https://drive.google.com/drive/folders/1BOPLlH_I8TjPL_-n-BS3vCa83EH6sjbb?usp=drive_link

Readme (also inside the assets folder)

STEPS FOLLOWED TO CREATE THE PROJECT:
- Imported Steam Audio. 
- Created demo scenario (cubes).
- Configured SteamAudio settings like my project. 
- Created AudioSource_A and configured it like my project. 
- Duplicated AudioSource_A and renamed to AudioSource_B.
- Created Steam Audio Material like my project. 
- Added Steam Audio Geometry and Steam Audio Static Mesh to Scenario GameObject.
- Added Steam Audio Geometry and Steam Audio Dynamic Object to both DynamicObject_X GameObjects.
- Exported Dynamic Objects and Export Active Scene.

Now for me, B door is occluding and A is not. 

There is a script attached to each dynamic object (orange ones) with a button to start/restart the moving process (open close doors).
On finish closing doorA, you can move the camera a little to stop playing the sound. 
jordihuertas commented 5 months ago

Remember to configure the project settings audio to use Steam Audio. With the imported project, Dynamic Objects will not occlude the audio when "close".

You can clone an audio source and disable the original copy to check that the new audio source will be occluded. If you do the same with the second one, the first one will stop working as expected (the door will not occlude the audio).

jordihuertas commented 5 months ago

Here is a demo video https://www.youtube.com/watch?v=TZgbQ0Pz5so&ab_channel=PepeGrillo

achandak commented 5 months ago

@jordihuertas - Thanks for providing a repro. We indeed found a bug where only one source was being updated when dynamic geometry was present. The fix is inside phonon.dll so we should have this fixed in the next release.

jordihuertas commented 5 months ago

I'm glad to hear that you finally found it!

lakulish commented 5 months ago

This issue should now be fixed in v4.5.1.

jordihuertas commented 4 months ago

Sorry for the late response, I had some problems when updating to 4.5.1 because some unity crashes related to git.

Retested. It works!

kisak-valve commented 4 months ago

Thanks for retesting. Closing.