I have some “hard coded” animation among a dialog sound (since I’m not using FaceFX). So when an animation starts, I play the dialog sound using a “Notify - PlaySound”. This works pretty much as I want to.
But how can I stop the sound when the animation is cut off before the end ? For now, the sound will just continue to play even if the animation is stopped.
What I found so far:
Use a custom C++ AnimInstance class which store all the possible sounds for my animations but it’s dirty as f*** and really not convenient.
Create a custom AnimNotifyState and overriding Received_NotifyBegin & Received_NotifyBegin for each animation which is better but still not very convenient.
///////////////////////////////////////////////////////////////////////////////
void UPOLICE_AnimNotifyState::NotifyEnd(USkeletalMeshComponent* MeshComp,
UAnimSequenceBase* Animation)
{
// Stop the sound if needed
if (m_AudioComponent)
{
m_AudioComponent->Stop();
m_AudioComponent = NULL;
}
}
Add the custom notify UPOLICE_AnimNotifyState in the animation notifies section and set its duration to the whole animation duration (so the notify will be alive during the whole animation).
Select the sound you want to play in the details panel.
Hello, how can you do this with blueprint? I tried to reproduce it, but seems not possible to get the “audio component” and stop it, can you please explain it a little bit? Thank you.
As you can see in my header file I’ve manually add an UAudioComponent and initialize it at runtime with UGameplayStatics::SpawnSoundAttached.
You can do this in blueprints to. Create a blueprint class inheriting from AnimNotifyState and add an Audio component in the components section. Then you should be able to do the exact same thing I did with C++
*Regarding on how the resume the sound, you just need to split the audio file, so when the animation is paused you cut the audio at that moment and when you resume it play the next audio file you splitted.
In C++ the YOURAnimNotifyState::NotifyEnd is automatically called when your notify ends (the notify you add in your animation) so you be able to override the same kind of event in your blueprint.
Also, how to stop it with the “stop” node?
The answer is in the question :D. Just use the stop node using the reference returned from SpawnSoundAttached
I don’t know about pausing and I didn’t explore this issue yet.
Sorry to bother you, but in notify blueprint you can’t set variables, can’t call functions within it, can’t create custom events, it’s very limited, how can you reference that SpawnSoundAttached in NotifyEnd?
Did you tried this in blueprint?
Can you post an image of what to be done?
Create a blueprint inheriting from AnimNotifyState
Create a variable of type Audio Component Reference and make it editable
Override the Recieved Notify Begin and Recieved Notify End function. In theses functions, you will be able to play and stop the AudioComponentReference you just created
In your animation, add a notify and select the notify type you just created at 1.
You should be able to select the sound to play in the animation directly ;). It should be the same thing we can see in my answer’s screenshot
I don’t know if it’s me that don’t understand, but with AudioComponent you can’t set a sound, you need a SoundBase reference to set a sound, also AudioComponent is empty, it doesn’t work…
Yeah sorry, you are right I mixed both. As you can see in my C++ header I have two member:
An USoundBase to hold the sound reference to play (you will be able to set the sound here)
An UAudioComponent to handle the player (so you will be able to play and stop the previous sound)
In Recieved Notify Begin, just do as you did in your previous comment, use SpawnSoundAttached and save the Audio Component Reference you get here. (But if I remember well, you may not be able to change the variable in the notify blueprint, which sucks)
In Recieved Notify End just call stop on your Audio Component Reference
If you can modify variable in the notify blueprint, just go for the C++ solution since it’s working (I used it already). Sometimes, you just can’t do what you need in blueprints.
Hey guys. Can you tell me what I am doing wrong? I keep going over the what y’all said and it looks identical doesn’t it? I created a new AnimNotify blueprint > clicked override in the functions and hit notify begin and end > created an audio component variable in my character blueprint > created a sound base variable in the AnimNotify blueprint > copied what Ross90 has and added the notify state to the character animation. But I keep getting this error. It is driving me up the wall.
Holy sh*t. This is a 7 year old post. Ok well it is the only thing I have seen on the internet exactly to what I want so hopefully someone knows what is being said here and can help me out