Download

Changing android mobile orientation in game

Hello,

I’m trying to make a game for android device. What I want is to have two difficulty levels. On Easy difficulty I want the game to run in Portrait mode and on Hard Difficulty I want the game to run in Landscape mode.

I could not find a way to implement this via blueprint.

I guessed this can be done by changing values in Engine.ini Orientation values during runtime via C++ I tried to change the config files via C++ but cannot make it work.

I don’t understand what I am missing. Please help.

Here, I tried this (Not so good with C++ at all)

I made two custom nodes.

One is to set the orientation to Landscape and the other one is to get the current orientation of the device.

To get the orientation -

include “Orientation.h”
include “OrientationChangeBP.h”
FString UOrientationChangeBP::GetCurrentOrientation()
{
FString Orientation; GConfig->GetString( TEXT("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings"), TEXT(“Orientation”), Orientation, GEngineIni );
return Orientation; GConfig->Flush(false, GGameIni);
}

To set the orientation to Landscape -

include “Orientation.h”
include “SetOrientation.h”

FString USetOrientation::SetCurrentOrientation()
{
FString Orientation=“Landscape”;
GConfig->SetString( TEXT("/Script/AndroidRuntimeSettings.AndroidRuntimeSettings"), TEXT(“Orientation”), TEXT(“Landscape”), GEngineIni );
return Orientation;
GConfig->Flush(false, GGameIni);
}

Though they work in editor. My default orientation is “Portrait”, I run the get orientation function and I get printscreen “Portrait” and when I run the set orientation function and then get orientation I get “Landscape”. but not the desired effect.

I wished this was in via blueprint as it feels so basic. This is the only thing that has me stuck.

Is their some way that through C++ making custom node you can modify the GameActivity.JAVA file in [Project]\Intermediate\Android\APK\src\com\epicgames\ue4

All I want is to someway have control on changing the orientation in my game.

It is annoying me XD