Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for allowing a sound played from Audio Playback Track from AnimationPlayer to play after animation has finished #10874

Open
imirui opened this issue Oct 1, 2024 · 1 comment

Comments

@imirui
Copy link

imirui commented Oct 1, 2024

Describe the project you are working on

I am working on a first person shooter game. I am attempting to find a method to play weapon sounds, and the main issue arises when a gun fires. The previous method (changing the stream of a specific audio player as an animationplayer key) is very time consuming, so I searched for another way. Enter: the Audio Playback track.
image

Describe the problem or limitation you are having in your project

The Audio Playback Track works fine if the sound doesn't last longer than the animation. It can play multiple at the same time, so it's great for sounds like magazine in/out, slide/bolt forward/back, etc. The problem is with firing sounds, since most firing animations last a very short duration compared to their sounds. For example, the animation of a DB Shotgun firing in my game lasts 14 frames at 24 fps, while the sound lasts until about frame 47. As soon as the animation ends, any and all Audio Playback tracks immediately stop whatever sounds they're playing. The same issue happens with Animation Playback tracks too.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The feature I am suggesting is a simple check box below the End Offset setting to allow the sound effect to continue after the animation ends.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

If enabled, the sound in the AudioStreamPlayer will continue after the animation itself has ended. Here's an example of how it would look in engine, if added.
image

If this enhancement will not be used often, can it be worked around with a few lines of script?

Currently, this can be worked around in three methods: You can have a separate animation player for sounds which has the play method called when you want to have the sound play, however, this still does not allow the same sound to overlap. You can also have an audio stream player, with the stream changed and the playing property set to true on that frame, but it still has the same problems. The last workaround that can be used is by writing your own code to do it, even with specifying a file to play and allowing for audio overlap, at the cost of never being able to hear the audio until runtime, and the call method being very slow since you have to copy the path to the sound. Two of these methods require adding a method call track, which is a very slow track to set up, and the last requires two keys to be used.

Is there a reason why this should be core and not an add-on in the asset library?

This should be a core addition to the engine as a way to extend the engine's functionality. It will significantly reduce time with adding sound effects, allowing for rapidly repeating sounds that last a long time like gun shots, impact sounds, and other similar sounds to be played at a specific time during an animation, using the built in Audio Playback track. It would also make the audio playback work how one would expect given the visuals, with the old way being optional if the sound should cease.

@Calinou
Copy link
Member

Calinou commented Oct 3, 2024

To be fair, I wonder why audio playback even has to be stopped once the animation is done playing in the first place. I can't see any legitimate use cases for this, since the sound cuts off abruptly and you don't want that in a polished game. (You might want a fade-out effect, in which case you'd be animating the AudioStreamPlayer's volume_db property over time manually.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants