Download

Change Audio Listener Position in a blueprint project

Hi guys,
This will sound like a total noob question and it is - while I have some experience with C# and Unity I have zero with C++ and UE4. Unfortunately at this stage I have no programmer to help and I’m kind of navigating in the dark.

So I need to create a blueprint function that will allow me to change the Audio Listener position and apparently that’s possible only in code as it’s not exposed to BP yet.
What I found so far:

https://answers.unrealengine.com/questions/28880/change-audio-listener-position.html
“After a look at the StrategyGame component I can confirm that this is the way to do it: derive APlayerController and override the GetAudioListenerPosition. It’s all in the StrategyPlayerController class!”


void AMyCodeTopDownPlayerController::GetAudioListenerPosition(FVector & OutLocation, FVector & OutFrontDir, FVector & OutRightDir)
{
    APawn* const Pawn = GetPawn();
    if (Pawn)
    {
        FVector ViewLocation;
        FRotator ViewRotation;
        ViewLocation = Pawn->GetActorLocation();
        ViewRotation = Pawn->GetActorRotation();

        const FRotationTranslationMatrix ViewRotationMatrix(ViewRotation, ViewLocation);

        OutLocation = ViewLocation;
        OutFrontDir = ViewRotationMatrix.GetUnitAxis( EAxis::X );
        OutRightDir = ViewRotationMatrix.GetUnitAxis( EAxis::Y );
    }
    else
    {
        Super::GetAudioListenerPosition(OutLocation, OutFrontDir, OutRightDir);
    }
}

I’m currently watching the Introduction to UE4 Programming.

One of the problems is that the project is based on the SideScroller BP and not the Code version but hopefully it is still possible to do it using File / Add Code To Project option.
The other problem is that I really don’t know where to go from here :slight_smile: As I said I’m really navigating in the dark so a bit more info and direction would be really helpful.

Thank you,
-Adrian