PhotonPeer Unreal Engine 4.8

Serphimera
edited June 2015 in Native
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, [b][u][color=#FF0000]ApplicationName[/color][/u][/b]))
	{
		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

Comments

  • Hi Serphimera.

    PhotonPeer expects a byte array of at maximum 32 elements.
    An easy way to achieve that is replacing
    [code2=cpp]FString ApplicationName = "MasterServer";[/code2]
    with
    [code2=cpp]nByte* ApplicationName = reinterpret_cast<nByte*>("MasterServer");[/code2]

    PS:
    I have seen that you have posted this exact same question to this forum, to forums.unrealengine.com and to our support-system.
    Please don't cross-post. We are looking at all those channels and cross-posting won't shorten the timespan until we respond.
  • Hi Kaiserludi,

    thanks for the quick answer and sorry for cross-posting :( . But using your suggested solution leads to

    DALGameInstance.h(40): error : In DALGameInstance: Unrecognized type 'nByte'

    in my includes there is now Common-cpp/inc/defines.h

    Edit:

    I thought it could appear because of the UPROPERTY so commented out that but now I get:

    error C2440: 'initializing' : cannot convert from 'const char [13]' to 'nByte *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  • Hi again.

    As you can see when having a look at the include dependencies of PhotonPeer.h, which are graphically visualized at http://doc-api.exitgames.com/en/onpremi ... 00244.html, it already includes Common-cpp/inc/defines.h, so code that includes PhotonPeer.h, should also know about type nByte without having to do additional includes.
  • Hi again,

    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&lt;nByte*&gt;("MMOServer");
    

    DALGameInstance.cpp
    if(!peer-&gt;connect(*ServerAddress, ApplicationName))
    

    Try to implement listener now and view. Thanks for your help.
  • error C2440: 'initializing' : cannot convert from 'const char [13]' to 'nByte *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Oops. Sorry, I totally forgot to put the reinterpret_cast into that code-snippet. I have fixed my original answer now.
    /* ToDo: Find a way to get nByte as UPROPERTY! */
    I see two possibilities here:
    a) Teach to UE what nByte is. That maybe (I don't really know if UE4 supports a way to have user-defined or 3rd party defined types as UPROPERTY without modifying its source) means modifying the UE source to include the photon Client or at least Common-cpp/inc/defines.h or to copy and paste the nByte typedef from that header over to Unreal.
    b) Don't use nByte when it comes to UPROPERTY, but use the underlying type to which it is defined, which is unsigned char. That might introduce problems if we should ever decide to change the definition for nByte - in that case you woul have to adjust such code on upgrading Photon. However I don't see us changing this definition in the foreseeable future.
  • 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&lt;nByte*&gt;(TCHAR_TO_UTF8(*appId));
    
    photonPeer = new ExitGames::Photon::PhotonPeer(*photonListener, ExitGames::Photon::ConnectionProtocol::UDP);
    photonPeer-&gt;connect(*serverAddress, convertedAppId);