Skip to content

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

Open
@imirui

Description

@imirui

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions