UE4 Android Screen Orientation
how do I switch from a landscape widget to portrait via Blueprint - UE4 AnswerHub
Hello, if you can help me? I have two widgets, 1 (Main Menu), 2 (Registration Screen). I want to set the main menu as: LANDSCAPE and the Registration screen as: PORTRAIT I need to know how to do this, it's very important to me, Any help will be welcome. Th
answers.unrealengine.com
This is going to be a little bit complicated as unreal engine 4 does not support orientation change via blueprint by default. You will need the Mobile Utils plugin by gameDNA
NOTE - This code is not perfect. I have been trying to extend android functionality using this plugin however the code is not refined. Follow these instructions to the last letter. I am not that good with C++ yet, you might have to change some code according to your need here and there.
This was done in quite a rush and I never got back to it.
- Find the file MobileUtils_APL in that and add this code -
- public boolean AndroidThunkJava_ToggleOrientation()
- {
- boolean result=false;
- int orientation=getResources().getConfiguration().orientation;
- if(orientation==Configuration.ORIENTATION_PORTRAIT){
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- result=true;
- }
- else if(orientation==Configuration.ORIENTATION_LANDSCAPE)
- {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- result=false;
- }
- return result;
- }
- in Plugins\MobileUtils-master\Source\MobileUtils\Classes\Interfaces\MobileUtilsInterface.h - add this
- virtual bool ToggleOrientation() = 0;
- in Plugins\MobileUtils-master\Source\MobileUtils\Classes\MobileUtilsBlueprintLibrary.h
- UFUNCTION(BlueprintCallable, Category = MobileUtils)
- static bool ToggleOrientation();
- In Plugins\MobileUtils-master\Source\MobileUtils\Private\Android\MobileUtilsPlatform.cpp
First Add this -
- jmethodID FMobileUtilsPlatform::ToggleOrientationMethod;
Then inside the constructor -
- FMobileUtilsPlatform::FMobileUtilsPlatform()
- {
- if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
- {
- ToggleOrientationMethod = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_ToggleOrientation", "()Z", false);
- }
- }
Then the method implementatio -
- bool FMobileUtilsPlatform::ToggleOrientation()
- {
- bool tResult = false;
- if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
- {
- tResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, FMobileUtilsPlatform::ToggleOrientationMethod);
- }
- return tResult;
- }
- Now go to Plugins\MobileUtils-master\Source\MobileUtils\Private\Android\MobileUtilsPlatform.h
add the signatures of the method -
virtual bool ToggleOrientation() override;
static jmethodID ToggleOrientationMethod;
- Now in Plugins\MobileUtils-master\Source\MobileUtils\Private\MobileUtilsBlueprintLibrary.cpp
- bool UMobileUtilsBlueprintLibrary::ToggleOrientation() { #if PLATFORM_ANDROID || PLATFORM_IOS return IMobileUtils::Get().GetPlatformInterface()->ToggleOrientation(); #else return false; #endif }
Save and compile.
Now in blueprint you should have a method called "Toggle Orientation" if everything is done right -
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import com.google.android.gms.common.ConnectionResult;
- import android.telephony.TelephonyManager;
- import android.provider.Settings.Secure;
- import android.net.wifi.WifiManager;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import android.content.pm.ActivityInfo;
유틸 깃허브
https://github.com/gameDNAstudio/MobileUtils
gameDNAstudio/MobileUtils
A plugin for Unreal Engine 4 that lets you integrate mobile utilities into your project. - gameDNAstudio/MobileUtils
github.com
4.23.0 버전이 마지막이라 실행시 경고가 떠서
플러그인 파일 수정
MobileUtils.uplugin
버전을 4.26.0 으로 변경함
4.23.0 이상이면 정상동작 하는듯