Using UE 4.10 I’ve noticed that the “Get Duration” node is not always getting the correct length from an audio source.
My setup is as follows:
I created a blueprint actor (its a pickup object) with a public variable of type “Sound Base” (Inset highlighted in green on the right). I then specify a sound cue depending on what I want the player to say in the Details Panel after placing an instance of the blueprint in the world.
Inside the Player Character I have the following setup (left):
I call the audio with a Do Once node to prevent the audio from overlapping if the player picks up multiple objects in rapid succession. I connect the Do Once to PlaySound2D then for debug purposes I connect this to a Disable input then a delay with the GetDuration node plugged into the Duration of the Delay followed by an Enable Input node after the delay and then connect the output of that into the reset of the DoOnce so it can be called again.
What I’ve noticed happening is sometimes the input will be enabled immediately after the audio file stops playing, but other times there’s a good 5 second delay at the end of the audio file before input is re-enabled. This leads me to believe that the “Get Duration” node is not getting the correct duration from the audio cue. I think I’ve narrowed down the source of the problem though. Some of the objects are using a cue file with a series of random wavs and rather than grabbing the Duration of the wav file chosen, its grabbing the duration of the longest wav in the group. So if I have 6 wav files and 5 are 1 second in duration and the 6th is 5 seconds in duration, then there’s a 4 second delay after playing any of the shorter wavs. Is there a way to fix this?
The solution was shown to me by Hurley in another post. You need to get the audio file from the array and then SET this as something like “Audio to play” then grab the duration from the set node. This prevents the setup from grabbing one random file for the audio to play and the length of another random file.
Try using a print string to your duration variable, are you seeing it change when fired between the various lengths your sound cues are or is it remaining at the 5 second time limit? How are you populating your Sound Base?
Yeah, like I said, the duration is always the same; it takes the longest wav from the cue and uses that as the duration. In this case, its 6.2 seconds even though I’m using 16 different wav files that range between 0.53 seconds to 6.2
Here’s a more detailed look at my setup:
Above is a screen shot showing the duration Print String value which is the same every time I pick up the object
Above is the event for my “ObjectSpecial” which is where the SoundBase variable is stored
Above is a screenshot of the NotClueGeneric_Cue file with 16 random wav files all of different lengths ranging from 0.53 - 6.2 seconds in length. It always outputs 6.2 seconds however which is my problem.
The screen shot in my first post shows the ThirdPersonCharacter blueprint and how I call the sound and tell it to play. Let me know if you need a more detailed breakdown of that as well.
In your timeline do you have it set to “Use Last Keyframe?” or is it set to always run through the full window?
The timeline isn’t used for the audio, Its used for a material fade. The audio is only set via the object blueprint so that I can specify a new audio file per pickup. Then its played through the blueprint as shown in the first post.
To be clear; inside the object special blueprint (screen with timeline) I created a variable of “Sound Base” and made it public and I set the “NotClueGenericRandom” cue file as the default value. Then inside the player pawn blueprint I cast to the ObjectSpecialBP via a line trace and then call the code shown in the first post. It always spits out 6.2 as the duration no matter what.
Do you have a sample project I can see this occurring in? It may help me determine what the root cause of the error is.
I could attempt to re-create it in another project after the weekend. I’m just wrapping up the final details for my first playtest for the game so it’ll have to wait till that’s finished.
Have you been able to create a sample project I can take a look at? I’ll be happy to once it is made available.
Yes, here’s a small project that I re-created with the same issue. Several wave files in a single clue hooked to a random node and the duration is always the same as the longest wav file in the group which in this case is 6.2 seconds.
I had a look through the project and believe this is working as expected. The sound file you are using takes the longest time of the wavs available and implements that as its duration. Instead, try using an array of sound wav files or sound cues (if you want to alter the sounds) that you randomly choose between, you can see a setup for that in the images below:
It is doing the same thing you were trying to do through the sound asset, but instead it takes the individual assets and randomizes them on the spot. This can also give you significantly more control as you can set each to an individual sound cue that is played and you can randomize the pitch, attenuation, etc. of each sound byte, that way you don’t have to worry about the length of time in each sound cue.
Ok. Just seems like a more complicated way of doing it and also a bit strange if the cue files already have a random wavs node. On top of which randomizing inside the cue gives you the ability to set Randomize without replacement which means that you never get the same audio file twice in a row whereas randomizing an array will be purely random which means you might get the same wav file twice. Also you can set the weight of certain wav files so that they are more or less likely to be played inside the cue, something else you can’t do with an array. I appreciate the workaround, but it seems like the functionality was built into the cue files but not fully implemented which is why I still think its a bug.
I double checked with our audio programmer to ensure my understanding was correct. The sound cue file will always return the full value of the longest .wav file within the cue. You can’t change the length because it is simply metadata being fed to the sound cue. To perform more complicated sound design logic, such as getting the length of each .wav file, you will have to break the sound .wavs into separate sound cues as detailed above. The method linked above is the simplest method to get the desired results you are looking for.
Ok. I guess that makes sense. The random wavs are more likely for things like weapon fire etc. where all the wavs are roughly the same length.
Is there any way to get the same kind of randomize without replacement option through a random array then? That’s the biggest downside to not using the cue files for me
Unfortunately if you need to get the specific length of the wav files no. This will be the most efficient method to do so.
So after several months I implemented the system using an array of wav files as you suggested and it’s still not working. Apologies, for some reason I decided to start a separate bug report rather than coming back to update this one. I could move my post over here if you’d like but here’s the issue:
Simply put, I think there’s an issue with the get duration node as I built out my array setup exactly as you suggested by the get duration is always incorrect (except for some reason on the first use it seems to work).