Voice chat overview
To access voice chat in EOS, you'll need to use the IVoiceChat
interface. You'll use this interface to create a voice chat user, and then "connect" that voice chat user to the EOS online subsystem (where you've already signed the user in).
Using the IVoiceChat interface
To access the IVoiceChat interface in C++, you'll need to:
- Reference the "VoiceChat" module in your
.Build.cs
file. - Include the "VoiceChat.h" header.
- Call the
IVoiceChat::Get()
static function to get a reference to the voice chat interface.
To get the voice chat interface in Online Subsystem Blueprints, use the "Online Voice Chat Subsystem" node.
In blueprints, the "Online Voice Subsystem" node is different to "Online Voice Chat Subsystem" node.
You want to use the "Online Voice Chat Subsystem" node.
The "Online Voice Subsystem" node is a legacy API for older games and should not be used to access EOS voice chat.
Understanding "voice chat users"
Instances of IVoiceChatUser
act as "windows" into the EOS online subsystem. You can have multiple instances of IVoiceChatUser
referencing the same local EOS user.
In C++, this is important, as instances of IVoiceChatUser
are not shared references. Thus it's not safe to share the pointer around in C++ in case it is later released with ReleaseUser
. Each part of your game that needs to control voice chat should have it's own IVoiceChatUser
instance and release it when it's no longer used.
In blueprints, Online Subsystem Blueprints wraps the IVoiceChatUser
pointer so that it is automatically released when there are no further references to it.
Creating a voice chat user
To create a voice chat user, use IVoiceChat->CreateUser()
. This user won't be connected to the EOS online subsystem until you call Login
on it, which tells it which local EOS user it maps to.
If you're using voice chat users in C++, you must also call IVoiceChat->ReleaseUser()
in Unreal Engine 4.26 when you're finished using the IVoiceChatUser
instance.
- C++
- Blueprints
IVoiceChat* VoiceChat = IVoiceChat::Get();
IVoiceChatUser* VoiceChatUser = VoiceChat->CreateUser();
// Store VoiceChatUser for the lifetime of your containing object or until you're otherwise finished with it.
// On Unreal Engine 4.26 and later only.
VoiceChat->ReleaseUser(VoiceChatUser);
Connecting the voice chat interface to EOS
Once you've created an IVoiceChatUser
instance, you need to connect it to the EOS online subsystem by calling Login
.
- C++
- Blueprints
To connect a voice chat user in C++, fetch the identity interface and use it to get both the unique net ID for the local user and their platform user ID. Then pass those values into the Login function of the IVoiceChatUser
instance you created.
This example also shows releasing the VoiceChatUser
instance during BeginDestroy
, to ensure that memory is not leaked when AMyClass
is garbage collected by Unreal Engine.
// MyClass.h
#include "Interfaces/OnlineIdentityInterface.h"
#include "VoiceChat.h"
class AMyClass : public AActor
{
GENERATED_BODY()
private:
IVoiceChatUser* VoiceChatUser;
void OnLoginComplete(const FString& PlayerName, const FVoiceChatResult& Result);
public:
virtual void BeginDestroy() override;
void DoLogin();
}
// MyClass.cpp
void AMyClass::DoLogin()
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
this->VoiceChatUser = VoiceChat->CreateUser();
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(0);
FPlatformUserId PlatformUserId = Identity->GetPlatformUserIdFromUniqueNetId(*UserId);
VoiceChatUser->Login(
PlatformUserId,
UserId->ToString(),
TEXT(""),
FOnVoiceChatLoginCompleteDelegate::CreateUObject(this, &AMyClass::OnLoginComplete));
}
void AMyClass::BeginDestroy()
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (this->VoiceChatUser != nullptr && VoiceChat != nullptr)
{
VoiceChat->ReleaseUser(this->VoiceChatUser);
this->VoiceChatUser = nullptr;
}
Super::BeginDestroy();
}
void AMyClass::OnLoginComplete(const FString& PlayerName, const FVoiceChatResult& Result)
{
if (Result.IsSuccess())
{
// You can now use this->VoiceChatUser to control the user's voice chat.
}
}
Testing voice chat
The EOS SDK provides an "echo" feature which allows you to test voice chat with only a single user. You can enable echo in the following ways:
- For parties, enable the "Enable Echo in Parties (Development Only)" option in Project Settings.
- For listen servers, set the "EOSVoiceChat_Echo" lobby attribute to "true" (boolean value).
- For dedicated servers, pass
EVoiceChatChannelType::Echo
when joining the channel.
The echo functionality does not appear to reliably work in EOS SDK 1.13.1. For now, it's recommended that you test voice chat by:
- Start two play-in-editor instances, each signed into a different EOS account using the Developer Authentication Tool.
- Set each play-in-editor instance to use a different input/output audio device. For example on a laptop you could use the laptop mic/speakers for one user, and a bluetooth headset for another. You need to select these audio devices through the
IVoiceChatUser
interface. - Join both users to voice chat.
The "is talking" status of voice chat users will always return false if there is only one user in the voice chat channel, even if you have echo enabled. If you want to use the "is talking" status, you must test with multiple players in voice chat.