Unreal Engine

All C++ based Photon SDKs are compatible with the UNREAL ENGINE off the shelf.

In detail the multiplayer SDKs you can gear up with the UNREAL ENGINE SDK are

You get all Photon SDKs from the Download page.

Get Started

Proceed as follows to integrate any of the compatible Photon multiplayer game SDKs with the UNREAL ENGINE SDK.

  1. Download the UNREAL ENGINE SDK.

  2. Download the Photon SDK for your targeted Platform.

  3. Only Unreal 'C++' projects are supported.

  4. Unpack the Photon SDK of your choice (Windows, Android or iOS) in the 'Photon' folder inside of the 'Source' folder of your Unreal project.
    Only the header files and pre-built libraries are required. You may want to add libraries for multiple different platforms.
    Sample folders layout:

    text

        \---Source
            +---Photon
            |    +---Common-cpp
            |    |    \---inc
            |    |        (*.h)
            |    +---LoadBalancing-cpp
            |    |    \---inc
            |    |        (*.h)
            |    |---Photon-cpp
            |    |    \---inc
            |    |        (*.h)
            |    +---lib
            |    |    +---Android 
            |    |        (*.a)
            |    |    +---iOS
            |    |        (*.a)
            |    |    \---Windows
            |    |        (*.lib)
    
  5. Modify the Photon headers to workaround an incompatibility with the Unreal headers.
    Rename FLOAT to EG_FLOAT, or apply Source\Photon\photon.patch from the reference project:

    C++

        Photon/Common-cpp/inc/Enums/TypeCode.h
        @@ -18,7 +18,7 @@
        -            static const nByte FLOAT              = 'f'; /**<float*/
        +            static const nByte EG_FLOAT           = 'f'; /**<float*/
        //
        Photon/Common-cpp/inc/Helpers/ConfirmAllowed.h
        @@ -76,7 +76,7 @@
        -            static const nByte typeName = TypeCode::FLOAT;
        +            static const nByte typeName = TypeCode::EG_FLOAT;
        //
        Photon/Common-cpp/inc/Helpers/ConfirmAllowedKey.h
        @@ -43,7 +43,7 @@
        -            static const nByte typeName = TypeCode::FLOAT;
        +            static const nByte typeName = TypeCode::EG_FLOAT;
    
  6. Edit the "*.Build.cs" file of the Unreal project to load the libraries for a given platform and to set Photons platform defines.
    See "Source/PhotonDemoParticle/PhotonDemoParticle.Build.cs" in the demo that is linked below and Unreal documentation:

    C#

    private string PhotonPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "..", "Photon")); }
    }
    //
    if ( Target.Platform == UnrealTargetPlatform.Android)
    {
        // Set _EG_WINDOWS_PLATFORM for Windows, _EG_IPHONE_PLATFORM for iOS and _EG_IMAC_PLATFORM for OS X
        Definitions.Add("_EG_ANDROID_PLATFORM");
        //
        PublicAdditionalLibraries.Add(Path.Combine(PhotonPath, "lib", "Android", "libcommon-cpp-static_debug_android_armeabi_no-rtti.a"));
        PublicAdditionalLibraries.Add(Path.Combine(PhotonPath, "lib", "Android", "libphoton-cpp-static_debug_android_armeabi_no-rtti.a"));
        PublicAdditionalLibraries.Add(Path.Combine(PhotonPath, "lib", "Android", "libloadbalancing-cpp-static_debug_android_armeabi_no-rtti.a"));
    }
    
  7. Include the appropriate Photon API headers in project sources with some workarounds;
    "source\photon-import.h" in the reference project:

    C++

        #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 "LoadBalancing-cpp/inc/Client.h"
        #pragma warning (default: 4263)
        #pragma warning (default: 4264)
        #if _EG_WINDOWS_PLATFORM
        #include "HideWindowsPlatformTypes.h"
        #endif
    
  8. Use the imported Photon API in the source code of your project.

  9. Build your Unreal project for your platform of choice.

Notes

Some hints regarding Unreal iOS builds can be found here.

Ready-to-run Demo

Find a ready-to-run proof of concept for download here

  • Follow steps 1 and 2 from above
  • Unzip the downloaded package
  • Follow step 4 from above
  • Open the context menu for "./PhotonDemoParticle.uproject" and choose "Generate Visual Studio project files"
  • If you have multiple different versions of unreal engine installed, choose the desired engine version and click OK
  • UE is now generating the project files. This may take a couple of seconds and UE will indicate that it has finished doing so only by letting the "Generating" message box disappear
  • Open "PhotonDemoParticle.sln" with Visual Studio
  • Choose "Win64" as solution platform
  • Choose "DebugGame_Editor" as solution configuration
  • In the solution explorer navigate to Games/PhotonDemoParticle and build that project
  • Debug or Run that VS project - this will start the UE editor with PhotonDemoParticle as loaded UE project
  • In the UE Editor "World Outliner" tab navigate to "PhotonLBClient" -> "Demo" -> "App ID"
  • Replace the content of that field with the App ID from your Dashboard on our Website
  • Press Play
Back to top