Integrate voice chat
AGS voice chat is currently only supported in Unreal Engine. Support for Unity is coming soon.
Overview
AccelByte Gaming Services (AGS) Chat includes voice chat. This article walks you through integrating push-to-talk voice chat into your game.
Prerequisites
To be able to complete all the steps in this article, you will need:
- Unreal
- Unreal Engine 4.27.2 or above
- Knowledge of using the OnlineSubsystem (OSS)
- The AGS SDK and OSS plugins installed into your project
Configuration
To support voice chat, configure the following settings in your game client:
- Unreal
[OnlineSubsystem]
bHasVoiceEnabled=true
[Voice]
bEnabled=true
[/Script/Engine.GameSession]
bRequiresPushToTalk=false
Register local and remote talkers
You can include local and remote talker registration in the Session class by calling the RegisterPlayers
method. This will simplify the process of adding players to voice chat, providing a seamless experience when they are joining a game session or party (as parties are a type of session).
- Unreal
FName SessionName;
TArray<TSharedRef<const FUniqueNetId>> Players;
bool bWasInvited;
SessionInterface->RegisterPlayers(SessionName, Players, bWasInvited);
Assign a button for push-to-talk
To enable push-to-talk, assign a button that players can use to turn on or off their microphone to talk with other players. This setup will vary from game to game. The following sample code shows how to set up the forward slash /
key to control the voice chat.
- Unreal
[/Script/Engine.InputSettings]
...
+ActionMappings=(ActionName="ToggleSpeak",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Slash)
void AGamePlayerController::BeginPlay()
{
...
#if !UE_SERVER
InputComponent->BindAction("ToggleSpeak", EInputEvent::IE_Pressed, this, &APlayerController::StartTalking);
InputComponent->BindAction("ToggleSpeak", EInputEvent::IE_Released, this, &APlayerController::StopTalking);
#endif
}
Known issues
- Unreal
There are some differences between a Windows server (local dedicated server) and a Linux server (Armada) that can lead to different behavior, such as a Linux server being unable to read push-to-talk settings. A Linux server can only use settings that are enabled by default. This means that the server will always send a command to disable network voice, requiring the game to implement a process to enable network voice so players can talk freely without pressing a key.
The voice chat feature has been tested and works for game sessions that run on dedicated servers, but it is currently untested in peer-to-peer (P2P) connections.
Troubleshooting
In this section, you can find common errors and issues that may occur when using the service, along with recommendations on how to resolve them.
- Unreal
Missing push-to-talk audio when testing two clients locally
When running two clients locally using push-to-talk, you may experience an issue hearing the voice chat in one client. This is because Unreal, by default, mutes the audio of an instance when its window loses focus. To resolve this when testing on the same machine, you can update the unfocused audio modifier in the DefaultEngine.ini to 1.0 instead of 0.0.
[Audio]
UnfocusedVolumeMultiplier=1.0