PhotonPeer Unreal Engine 4.8

Hello there,

I´m trying to implement PhotonPeer in Unreal Engine 4.8 but stuck at the connect function. I need to provide a AppId, but nothig I try is accepted by UE4.

Here’s my code:

DALGameInstance.h



// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Engine/GameInstance.h"
#ifdef __clang__
#pragma clang diagnostic ignored "-Woverloaded-virtual"
#endif
#if _EG_WINDOWS_PLATFORM
#include "AllowWindowsPlatformTypes.h"
#endif
#pragma warning (disable: 4263)
#pragma warning (disable: 4264)
#include "Photon/Photon-cpp/inc/PhotonPeer.h"
#include "Photon/Photon-cpp/inc/PhotonListener.h"
#pragma warning (default: 4263)
#pragma warning (default: 4264)
#if _EG_WINDOWS_PLATFORM
#include "HideWindowsPlatformTypes.h"
#endif
#include "DALGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class DALGAME_API UDALGameInstance : public UGameInstance
{
	GENERATED_UCLASS_BODY()
	
public:
	//UDALGameInstance(const class FObjectInitializer& ObjectInitializer);
	ExitGames::Photon::PhotonPeer* peer;
	ExitGames::Photon::PhotonListener* listener;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DALGameInstancePhoton)
	FString ServerAddress = "127.0.0.1:5055";
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DALGameInstancePhoton)
	FString ApplicationName = "MasterServer";
};


DALGameInstance.cpp



// Fill out your copyright notice in the Description page of Project Settings.

#include "DALGame.h"
#include "DALGameInstance.h"

UDALGameInstance::UDALGameInstance(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	peer = new ExitGames::Photon::PhotonPeer(*listener, ExitGames::Photon::ConnectionProtocol::UDP);
	UE_LOG(LogTemp, Warning, TEXT("Connecting to server"));
	if(!peer->connect(*ServerAddress, **ApplicationName**))
	{
		UE_LOG(LogTemp, Warning, TEXT("Connection failed"));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Connection established"));
	}
}


The red part is the problem. BuildTool complains No suitable conversion from FString to const nByte. I have tried everything to get this up and running but no chance at all.

Has someone the same issue or an hint what I missed?

Thanks in advance

You’re going to have to make a conversion function for FString to const nByte. The Photon API doesn’t know what an FString is.

Can u give me an example or hint? is it something like “TCHAR* chars = *MyString; FString::Printf(TEXT(“Hello, the contents of My String is: %s”), *MyString);” ?

Hi .

I have given you an answer at http://forum.exitgames.com/viewtopic.php?p=23752#p23752.

Hi again,

thanks for the answer over at exitgames. Found a solution so far with this:

DALGameInstance.h


    /* ToDo: Find a way to get nByte as UPROPERTY! */
    //UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DALGameInstancePhoton)
    nByte* ApplicationName = reinterpret_cast<nByte*>("MMOServer");

DALGameInstance.cpp


    if(!peer->connect(*ServerAddress, ApplicationName))

Try to implement listener now and view. Thanks for your help.

As an alternative, if you want to make “ApplicationName” a UPROPERTY again, you could try casting it right before you call connect.

Like this:

DALGameInstance.h


    
/* ToDo: Find a way to get nByte as UPROPERTY! */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DALGameInstancePhoton)
FString ApplicationName;



DALGameInstance.cpp


    
nByte* ConvertedApplicationName = reinterpret_cast<nByte*>(*ApplicationName);

if(!peer->connect(*ServerAddress, ConvertedApplicationName))


That’s assuming that “TCHAR *” can be converted to “nByte *”. If not, you can try converting the FString to “const char *”, and then try converting to “nByte *”.

You can have a look at this for the FString to const char * conversion (Specifically, the “ConvertToCCP(FString str)” function): Here

A little bit late (no time for programming) I found a solution:

in .h :


UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "ETY")
FString serverAddress;
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "ETY")
FString appId;

and then in .cpp :


serverAddress = "127.0.0.1:5055";
appId = "MasterServer";

nByte* convertedAppId = reinterpret_cast<nByte*>(TCHAR_TO_UTF8(*appId));

photonPeer = new ExitGames::Photon::PhotonPeer(*photonListener, ExitGames::Photon::ConnectionProtocol::UDP);
photonPeer->connect(*serverAddress, convertedAppId);