Why cant i get voice chat interface?

void UAdvancedVoiceLibrary::StartNetworkedVoice(uint8 LocalPlayerNum)
{
IOnlineVoicePtr VoiceInterface = Online::GetVoiceInterface();

if (!VoiceInterface.IsValid())
{
	UE_LOG(AdvancedVoiceLog, Warning, TEXT("Start Networked Voice couldn't get the voice interface!"));
	return;
}

VoiceInterface->StartNetworkedVoice(LocalPlayerNum);

}

IsValid() always false, and voice chat not working.
Here is my DefaultEngine:

[Voice]

bEnabled=true

[OnlineSubsystem]

DefaultPlatformService=Steam

bHasVoiceEnabled=true

[OnlineSubsystemSteam]

bEnabled=true
1 Like

Hey @Kokapuk , I have also been scratching my head on why this wasn’t working. After looking into it a bit, it seems like we need to add “GetWorld()” to the “Online::GetVoiceInterface()” like this:

IOnlineVoicePtr VoiceInterface = Online::GetVoiceInterface(GetWorld());

However, I see that you are using the “UAdvancedVoiceLibrary” in that case you would want to modify the AdvancedVoiceLibrary.cpp/.h to have each of the functions containing:

IOnlineVoicePtr VoiceInterface = Online::GetVoiceInterface();

to have a new param “const UObject* WorldContextObject” since a UBlueprintFunctionLibrary does not have a UObject out right to reference the UWorld.

e.g.

AdvancedVoiceLibrary.h

UFUNCTION(BlueprintCallable, Category = Online|AdvancedVoice, meta = (WorldContext = "WorldContextObject"))
static void StartNetworkedVoice(const UObject* WorldContextObject, uint8 LocalPlayerNum = 0);
AdvancedVoiceLibrary.cpp

void UAdvancedVoiceLibrary::StartNetworkedVoice(const UObject* WorldContextObject, uint8 LocalPlayerNum)
{
	if (!IsValid(WorldContextObject))
	{
		UE_LOG(AdvancedVoiceLog, Warning, TEXT("No valid UObject to use to get World!"));
		return;
	}

	IOnlineVoicePtr VoiceInterface = Online::GetVoiceInterface(WorldContextObject->GetWorld());

	if (!VoiceInterface.IsValid())
	{
		UE_LOG(AdvancedVoiceLog, Warning, TEXT("Start Networked Voice couldn't get the voice interface!"));
		return;
	}

	VoiceInterface->StartNetworkedVoice(LocalPlayerNum);
}

Also something to note: when using these functions now is that they will automatically take the UObject Context of whatever they are getting called within.

I am not 100% on the reason why but it seems to be on the lines of a call to GetOnlineSubSystem() during the Init() of FVoiceEngineImpl - during the Init() of FOnlineVoiceImpl - returns a nullptr to a IOnlineSubsystem* variable which then makes the VoiceInterface invalid. I think this happens because without directly saying that we want the VoiceInterface for the UWorld, we were trying to create another one.