This is meant to broadcast value every time i pause/unpause my audio in blueprint and then execute more code logic depending on
broadcasted value.
So I assume you try to:
- Inform other objects in game, that audio playback state is changed
- Provide C++ and Blueprint implementation for playback change in your audio controller
My proposition is to create inner UAudioController
implementation of playback change using BlueprintNativeEvent
. Base C++ implementation will use your dispatcher to propagate notification to other game objects.
This is class .h file in short.
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( FSoundPausedDelegate, bool, isSoundPaused );
...
//Convenient Play/Pause function for blueprint
UFUNCTION( BlueprintCallable, Category="Example" )
void Play();
UFUNCTION( BlueprintCallable, Category="Example" )
void Pause();
//Implementation for pause state change
UFUNCTION( BlueprintNativeEvent, Category="Example" )
void OnSoundPaused( bool paused );
void OnSoundPaused_Implementation( bool paused );
...
//event dispatcher
UPROPERTY( VisibleAnywhere, BlueprintAssignable )
FSoundPausedDelegate AudioPauseEvent;
Convenient functions simply call implementation:
void UAudioController::Play()
{
OnSoundPaused( false );
}
void UAudioController::Pause()
{
OnSoundPaused( true );
}
Implementation is defined first as C++ code, which also fire AudioPauseEvent
with Broadcast
function:
void UAudioController::OnSoundPaused_Implementation( bool paused )
{
if( paused == true )
{
SoundPause = true;
GEngine->AddOnScreenDebugMessage( -1, 5.f, FColor::Red, TEXT( "True" ) );
// more logic...
}
else
{
SoundPause = false;
GEngine->AddOnScreenDebugMessage( -1, 5.f, FColor::Red, TEXT( "False" ) );
// more logic...
}
AudioPauseEvent.Broadcast( SoundPause );
}
Implementation of OnSoundPaused
could be then overridden in Bluepint derived from UAudioController
:

Having AudioPauseEvent
let you to notify other game objects. Example below show how to subscribe for pause change in level blueprint:

You could also subscribe other objects (for example UAudioListener
) from C++ for this event:
void UAudioListener::StartListeningForAudioPause()
{
// UAudioListener::OnAudioPause should be UFUNCTION
AudioControllerPtr->AudioPauseEvent.AddDynamic( this, &UAudioListener::OnAudioPause );
}