Skip to content

Unreal Engine 4

This guide explains the tasks to perform after installing the Hive SDK.

Setting the auto-rotate screen feature

When setting the screen orientation to both landscape and portrait, the following settings are required.

Android

For Android app builds, if you want to set the screen orientation to both landscape and portrait and ensure that the auto-rotate feature works properly, you need to modify the following code.

  1. Navigate to /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.template.
  2. Add the HiveActivity.onConfigurationChaged() API.
    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
    HiveActivity.onConfigurationChanged(this, newConfig); // Add
    super.onConfigurationChanged(newConfig);
    
    
    // forward the orientation
    boolean bPortrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT;
    nativeOnConfigurationChanged(bPortrait);
    }
    

iOS

For iOS, to ensure that the additional bi-directional settings work correctly, you need to implement the screen rotation-related method application(_:supportedInterfaceOrientationsFor:) in the Unreal Engine IOSAppDelegate.cpp file. This method's return value should return the UIInterfaceOrientationMask value to be applied to the game. A landscape-only game returns landscape, a portrait-only game returns portrait, and a game that supports both landscape and portrait returns both landscape and portrait.

Add the following code to /Engine/Source/Runtime/ApplicationCore/Private/IOS/IOSAppDelegate.cpp.

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  // TODO: Landscape-only game
  return UIInterfaceOrientationMaskLandscape;
  // TODO: Portrait-only game
  return UIInterfaceOrientationMaskPortrait;
  // TODO: Game supporting both landscape and portrait
  return UIInterfaceOrientationMaskAll;
}

Setting Swift compatibility (iOS)

In the iOS development environment, to ensure compatibility between Unreal Engine 4 and the Swift language, add the lines marked with 'Add' comments in the following files (from Add to Add End).

Engine/Source/Programs/UnrealBuildTool/ProjectFiles/Xcode/XcodeProject.cs

    {
       Content.Append("\t\t\t\t\"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]\" = " + IOS_BUNDLE + ";" + ProjectFileGenerator.NewLine);
   }
   // Add
   if (ProjectFile != null)
   {
       Content.Append("\t\t\t\tSWIFT_VERSION = 5.0;" + ProjectFileGenerator.NewLine);
       Content.Append("\t\t\t\tSWIFT_OBJC_BRIDGING_HEADER = \"" + GamePath + "/dummy-Bridging-Header.h\";" + ProjectFileGenerator.NewLine);
   }
   // Add End
}
if (TVOSRunTimeVersion != null)
{
if (XcodeProjectFileGenerator.bGeneratingRunIOSProject)
{
   Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
   Content.Append("\t\t\t\tINFOPLIST_FILE = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
   Content.Append("\t\t\t\tCODE_SIGN_ENTITLEMENTS = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}

Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=macosx*]\" = \"" + MacInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
if (IOSRunTimeVersion != null)
{
   Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
   Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=iphoneos*]\" = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
   Content.Append("\t\t\t\t\"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]\" = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}

Engine/Source/Programs/UnrealBuildTool/Platform/IOS/IOSToolChain.cs

    Result += " -Xlinker \\\"" + Path.GetDirectoryName(OutputFile.AbsolutePath) + "\\\"";
}
Result += " -Xlinker -rpath -Xlinker /usr/lib/swift";  // Add
Result += " -dead_strip";
Result += " -m" + GetXcodeMinVersionParam() + "=" + ProjectSettings.RuntimeVersion;
Result += " -Wl";

Applying HIVEAppDelegate (iOS)

In the iOS development environment, modify the AppDelegate using Swizzling to use the Hive SDK. Add the following code during the initialization step at the start of the app.

////////////////////////////////////////////////////////////////
// Add IOSAppDelegate.h header
#if PLATFORM_IOS
#include "Runtime/ApplicationCore/Public/iOS/IOSAppDelegate.h"
#endif
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
// AppDelegate additional code
#if PLATFORM_IOS
UIApplication * dummyApplication = [UIApplication sharedApplication];

Class clzHIVEAppDelegate = NSClassFromString(@"HIVEAppDelegate");
SEL selApplicationDidFinishLaunchingWithOptions = NSSelectorFromString(@"application:didFinishLaunchingWithOptions:");
if( clzHIVEAppDelegate != nil && [clzHIVEAppDelegate respondsToSelector:selApplicationDidFinishLaunchingWithOptions] ) {
    NSMethodSignature *method = [clzHIVEAppDelegate methodSignatureForSelector:selApplicationDidFinishLaunchingWithOptions];
    if (method != nil) {

        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method];
        [invocation setSelector:selApplicationDidFinishLaunchingWithOptions];
        [invocation setTarget:clzHIVEAppDelegate];
        [invocation setArgument:(void*)&dummyApplication atIndex:2];
        NSDictionary *localLaunchOptions = [IOSAppDelegate GetDelegate].launchOptions;
        if( localLaunchOptions != nil ) {
            [invocation setArgument:(void*)&localLaunchOptions atIndex:3];
        }
        [invocation invoke];
    }
}
#endif
////////////////////////////////////////////////////////////////

In iOS development environment, you need to apply a promotion code as a prerequisite for deep link operation in the app shutdown state.

The promotion code is required to pass the schemes called as deep links to the Hive SDK after calling FHiveAuthV4::Setup(const FHiveAuthV4OnSetupDelegate& Delegate) before calling FHiveAuthV4::Setup(const FHiveAuthV4OnSetupDelegate& Delegate).

Add the promotion code as follows at the GameInstance init time.

//HIVEV4TesterPlatformGameInstance.cpp

#if PLATFORM_IOS
#include "Runtime/ApplicationCore/Public/iOS/IOSAppDelegate.h"
#endif

void UHIVEV4TesterPlatformGameInstance::Init()
{
#if PLATFORM_IOS
 FIOSCoreDelegates::OnOpenURLwithOptions.AddUObject(this, &UHIVEV4TesterPlatformGameInstance::ApplicationOpenURL);
#endif
}


void UHIVEV4TesterPlatformGameInstance::ApplicationOpenURL(UIApplication* application, NSURL* url, NSDictionary* options)
{
#if PLATFORM_IOS
 // Process the URL with HIVE SDK
 Promotion::processURI(std::string([[url absoluteString] UTF8String]));
#endif
}

Setting FmallocAnsi (iOS)

To ensure compatibility between Unreal Engine iOS and the C++ Standard Template Library, you need to configure FMallocAnsi as follows. Add the following code to your app project's {YourProject}.Target.cs file.

public class YourProjectTarget : TargetRules
{
    public YourProjectTarget(TargetInfo Target) : base(Target)
    {  
        // Force ANSI allocator for the app client
        if(Target.Platform == UnrealTargetPlatform.IOS)
        {
            GlobalDefinitions.Add("FORCE_ANSI_ALLOCATOR=1");
        }
    }
}