How do I switch from a landscape widget to portrait via Blueprint

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.

Thank you in advance!

Why don’t you just use the “custom size” in the designer panel and set them to whatever “landscape” and “portrait” size you like?

Do you want the orientation to change in Android?

Yes that’s right, it’s to run on the Android System

Yes, I have done this, but however, when I open this in android, the menu is in normal landscape mode, however, the signup screen is deformed with landscape resolution and not portrait

I set the orientation as landscape sensor

When changing the widget, I want Orientation to be set to Portrait

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.

  1. Find the file MobileUtils_APL in that and add this code -

    public boolean AndroidThunkJava_ToggleOrientation()
    boolean result=false;
    int orientation=getResources().getConfiguration().orientation;
    else if(orientation==Configuration.ORIENTATION_LANDSCAPE)
    return result;
  2. in Plugins\MobileUtils-master\Source\MobileUtils\Classes\Interfaces\MobileUtilsInterface.h - add this

    virtual bool ToggleOrientation() = 0;

  3. in Plugins\MobileUtils-master\Source\MobileUtils\Classes\MobileUtilsBlueprintLibrary.h

    UFUNCTION(BlueprintCallable, Category = MobileUtils)
    static bool ToggleOrientation();
  4. In Plugins\MobileUtils-master\Source\MobileUtils\Private\Android\MobileUtilsPlatform.cpp

First Add this -

jmethodID FMobileUtilsPlatform::ToggleOrientationMethod;

Then inside the constructor -

	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;
  1. 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;

  1. Now in Plugins\MobileUtils-master\Source\MobileUtils\Private\MobileUtilsBlueprintLibrary.cpp

    bool UMobileUtilsBlueprintLibrary::ToggleOrientation()
    return IMobileUtils::Get().GetPlatformInterface()->ToggleOrientation();
    return false;

Save and compile.

Now in blueprint you should have a method called “Toggle Orientation” if everything is done right -


Thank you very much !! I will try this

Ok, I have checked this again. It works, every time you call this function it will change your orientation. Maybe, you can customize it to have more control over which orientation you want (Like sensor). A lot of cleaning work needs to be done as it is amateurish One thing that I forgot to mention was the imports, your imports in the APL file should look like this -

import android.telephony.TelephonyManager;
import android.provider.Settings.Secure;