Skip to content

Latest commit

 

History

History
118 lines (77 loc) · 6.19 KB

ue4.md

File metadata and controls

118 lines (77 loc) · 6.19 KB

UE4 Integration

Details how we integrated Ruyi C++ SDK with Unreal Engine 4.

Also see packaging instructions.

Prerequisites

Using SDK Binary

Here we detail adding the precompiled SDK binary to the UE4 demo. The same process can be followed for other UE4 projects, substituting PlatformerGame with the name of your project.

  1. Download the latest SDK release

  2. The C++ SDK contains two folders: include/ and lib/. Copy them to your UE4 module source folder. E.g.: Source/PlatformerGame/RuyiSDK/include and Source/PlatformerGame/RuyiSDK/lib.

  3. Open Source/PlatformerGame/PlatformerGame.Build.cs

  4. Add using System.IO; to the top of the file. Bind lib path with:

     private string ModulePath
     {
         get { return ModuleDirectory; }
     }
    
     private string LibPath
     {
         get { return Path.GetFullPath(Path.Combine(ModulePath, "RuyiSDK/lib/")); }
     }
    
  5. Inside the constructor public PlatformerGame(ReadOnlyTargetRules Target) add SDK paths to the PublicIncludePaths property:

     PublicIncludePaths.AddRange(
         new string[] {
             "PlatformerGame/RuyiSDK/include",
             "PlatformerGame/RuyiSDK/include/Generated/CommonType",
         });
    
  6. Enable RTTI and exceptions for boost:

     bUseRTTI = true;
     bEnableExceptions = true;
     Definitions.Add("BOOST_ALL_DYN_LINK");
    
  7. Specify libraries:

     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "RuyiSDK.lib"));
     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "zmq", "libzmq.lib"));
     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "boost", "boost_chrono-vc141-mt-1_64.lib"));
     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "boost", "boost_date_time-vc141-mt-1_64.lib"));
     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "boost", "boost_system-vc141-mt-1_64.lib"));
     PublicAdditionalLibraries.Add(Path.Combine(LibPath, "boost", "boost_thread-vc141-mt-1_64.lib"));
    
  8. Copy runtime libraries lib/zmq/libzmq.dll and lib/boost/*.dll to the build output folder: Binaries/Win64.

  9. Open your project with Unreal Engine 4 Editor. Click File -> Refresh Visual Studio Project (or right-click PlatformerGame.uproject file and click Generate visual studio project file). Wait for it to finish, then reload your Visual Studio project and you will find include and lib folders in Solution Explorer (click View -> Solution Explorer).

  10. When using SDK functions, include RuyiSDK.h and use apprpropriate namespaces (like Ruyi::RuyiSDK). Refer to the SDK documentation for API details.

  11. Build your project.

Building SDK Binary

You can also use a binary built from the SDK source.

  1. Build SDK Binary

  2. From RuyiSDKCpp\bin\Release, copy the include and lib folders to your main module (e.g. Source/PlatformerGame/RuyiSDK/).

  3. Follow remainder of instructions from "Using SDK Binary"

Visual Studio 2015

UE4 supports several version of Visual Studio. Starting with 4.20 VS 2017 is the default.

Generating VS 2017 Projects

When VS 2017/v141 is not the default, you can generate VS project files on command line with -2017 param:

UnrealBuildTool.exe -projectfiles -project="C:/XXX.uproject" -game -engine -progress -2017

If it stills use v140 toolset:

  1. Open Registry Editor by running regedit
  2. Locate HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VC7
  3. Normally there is "14.0" and "15.0" keys. Delete "14.0". And, if it doesn't exist already, create "15.0" with value data of the install path of Visual Studio 2017 (e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC).
  4. Re-generate the project files on command line (using -2017 again)
  5. Open the sln project file, compile it, it should work fine.
  6. You can add the "14.0" key back after you generate the project files

v140

To target v140, you'll need to rebuild our SDK and all it's dependencies.

  1. Build SDK Binary, making sure all binaries target v140:

    • Boost can be built with b2 toolset=msvc-14.0 address-model=64 --build-type=complete stage
    • For libraries with Visual Studio projects, right-click a project and select Properties, for Platform Toolset select Visual Studio 2015 (v140):
  2. Follow remainder of instructions from "Building SDK Binary"

Known Issues

  • Since the SDK uses boost, you may encounter error LNK2038: mismatch detected for 'boost__type_index__abi': value 'RTTI is used'. You can solve this by adding bUseRTTI = true; to xxxx.build.cs.

  • Similarly: Error C4577: 'noexcept' used with no exception handling mode specified. You can solve this by adding bEnableExceptions = true; to xxx.build.cs.

  • If you encounter:

      RuyiSDK.lib(RuyiNetService.obj) : error LNK2001: unresolved external symbol __std_reverse_trivially_swappable_1
      RuyiSDK.lib(RuyiNetVideoService.obj) : error LNK2001: unresolved external symbol __std_reverse_trivially_swappable_1
      RuyiSDK.lib(RuyiNetGamificationService.obj) : error LNK2001: unresolved external symbol __std_reverse_trivially_swappable_1
      D:\usr\sample_ue4_demo\Binaries\Win64\UE4Editor-RuyiSDKDemo.dll : fatal error LNK1120: 1 unresolved externals
    

This is caused by UE4 using v140 toolset while our C++ SDK binary is compiled with v141. You need to do one of: