Sometimes we might wish to seek into a specific position of a playing sound. The Wwise integration doesn’t provide a blueprint node for that, but we can easily modify the source code to add a new blueprint node that makes this possible for an Ak Component.
Open up your IDE and declare a new function named Seek
in the AkGameplayStatics
header file:
UFUNCTION(BlueprintCallable, Category = "Audiokinetic")
static void Seek(UAkComponent* GameObjectAkComponent, int32 MilliSeconds, int32 PlayingID);
Then implement the function in AkGamePlayStatics.cpp
:
void UAkGameplayStatics::Seek(UAkComponent* GameObjectAkComponent, int32 MilliSeconds, int32 PlayingID)
{
AkUniqueID EventID = AK::SoundEngine::Query::GetEventIDFromPlayingID((AkPlayingID)PlayingID);
AkGameObjectID GameObjectID = GameObjectAkComponent->GetAkGameObjectID();
auto Result = AK::SoundEngine::SeekOnEvent(EventID, GameObjectID, (AkTimeMs)MilliSeconds, false, (AkPlayingID)PlayingID);
if (Result != AKRESULT::AK_Success)
{
UE_LOG(LogScript, Warning, TEXT("UAkGameplayStatics::Seek: Failed"));
}
}
The seek functionality works thanks to AK::SoundEngine::SeekOnEvent
. This function takes a few parameters we need to get first before calling it. The first argument is an AkUniqueID
which we can get by calling AK::SoundEngine::Query::GetEventIDFromPlayingID
and passing our AkPlayingID
as an argument. Alternatively, we could also pass the event’s name to the function. We need to pass an AkGameObjectID
as the second argument and we can get that by calling GetAkGameObjectID
on the UAkComponent
. Finally, we pass the position we want to seek to (as milliseconds) and the AkPlayingID
as the last two arguments.
Compile the project and you will able to use the new Seek blueprint node as we can see in this example:
Connect your spawned or referenced Ak Component to the Game Object Ak Component input pin. You can get the Playing ID by using the Post Ak Event or Post Associated Ak Event nodes instead of auto posting the event in the Ak Component. Happy seeking! 😊