UNAmedia Help

Documentation & Support

User Tools

Site Tools


ue5-multiworld:fmod

FMOD integration

User Kubstoff kindly tracked down an issue in FMOD (method FFMODStudioModule::UpdateWorldListeners()), where played sounds are not reproduced when multiple UWorld instances are active. Thanks Kubstoff!

Source: https://discord.com/channels/898503629655408660/898527948901089283/1108753001046347836


I finally had some time to investigate this ancient bug in the project and I managed to solve the issue, the gist of it was that in FFMODStudioModule::UpdateWorldListeners the Iterator is gotten from Iterator = GEngine→GetLocalPlayerIterator(World), this is the part where it conflicts with the plugin, it needs to update all player controller listeners for a given world, thus it should use Iterator = World→GetPlayerControllerIterator() what's mind boggling is that the functions name suggests that it wants to update the World listeners, dunno why they did it that way. anyways, if anyone is curious, getting this to work basically means that in the FMOD integration you need to swap the definition for FFMODStudioModule::UpdateWorldListeners to

UpdateWorldListeners-fix.cpp
void FFMODStudioModule::UpdateWorldListeners(UWorld *World, int *ListenerIndex)
{
    if (!World)
    {
        return;
    }
 
    float DeltaSeconds = World->GetDeltaSeconds();
 
    for (auto Iterator = World->GetPlayerControllerIterator(); Iterator; ++Iterator)
    {
        TWeakObjectPtr<APlayerController> LocalPlayer = *Iterator;
 
        if (LocalPlayer.IsValid())
        {
            APlayerController* PlayerController = LocalPlayer.Get();
            FVector Location;
            FVector ProjFront;
            FVector ProjRight;
            PlayerController->GetAudioListenerPosition(Location, ProjFront, ProjRight);
            FVector ProjUp = FVector::CrossProduct(ProjFront, ProjRight);
 
            FTransform ListenerTransform(FRotationMatrix::MakeFromXY(ProjFront, ProjRight));
            ListenerTransform.SetTranslation(Location);
            ListenerTransform.NormalizeRotation();
 
            SetListenerPosition(*ListenerIndex, World, ListenerTransform, DeltaSeconds);
 
            (*ListenerIndex)++;
        }
    }
}
ue5-multiworld/fmod.txt · Last modified: 2023/05/19 21:09 by Staff