Download

AudioComponent spatialization issue

We are trying to spatialize voice chat. When we create/join a session we are able to get the AudioComponents related to the users’ voices. We are also able to know which AudioComponent belongs to which Character. We are having problems in spatialization.
The problem is not the spatialization itself, nor the attenuation. We are able to hear the voice originating from the Character’s position and attenuated based on the Character’s distance.

I’ll try to describe our issue:

  • We attach the AudioComponent to the related Character’s RootComponent
  • If the user to which that character belongs stops talking, when it start to talk again its voice has moved with him
  • If the user never stops talking, its voice remains where he was when he started to talk…

We tried to draw a Debug sphere in the place where the AudioComponent is, and it correctly follows the Character (to which it is attached) also while the player is talking. So the problem is not the “attaching”; the problem is that the voice does not originate from the Character’s position (unless the player stops and starts to talk again).

Is there something we are forgetting to have the AudioComponent behaving correctly?

You need to perform the attachment before the audio component plays. If you need to do a reattachment, you need to stop then restart the audio component because it needs to be attached on “Play”. See UGameplayStatics::SpawnSoundAttached for the intended use-case of playing attached. There needs to be an association of the audio component and any playing active sounds. You can add some debug logging UAudioComponent::OnUpdateTransform to see what’s going on with your audio component – maybe it’s not updating any active sound transforms?

It’s also not supported to change whether or not a sound plays with HRTF spatialization once it starts playing.

You say: “You need to perform the attachment before the audio component plays. If you need to do a reattachment, you need to stop then restart the audio component because it needs to be attached on “Play”.”

I already stop the AudioComponent, then attach it and finally I play it again. The problem is that, when the Character to which the AudioComponent is attached moves, the AudioComponent seems not to follow it. Now I tried to continuously call Stop/Play on the AudioComponent, and actually it follows the Character.
But it seems to me not so clean to call Stop/Start in order to have the sound to follow the Character…