Is there any way to toggle android’s ‘render outside safe area’ option from script? I’d like to make it a menu option incase new devices with unanticipated screen cutouts are released that break my UI so users can switch it on/off to their liking.
Nah, i mean at runtime.
Right, apologies.
It’s available in the engine itself, in the native code, but looks like it’s not exposed to C# (scripts).
This may be a big issue - have mobile app that starts outside VR and when enters VR the display is offset by safe area and looks wrong
Same offset issue here with VR on Unity 2019.2.21 & LWRP.
Possible to make it available to C#?
We are having an issue where after we turned on Render Outside SafeArea under PlayerSettings but it will have a problem for android devices with a notch which running on Android 8.
So if we can change the behavior on the script at least we can choose to turn off Render Outside SafeArea for older devices.
No change, no plan on this one?
You may well want a video/cut-scene etc to run full screen while the rest is in the safe area and a simple runtime toggle just makes things a little easier
No update on this? Is this still not possible?
No update on this? Is this still not possible?
Is this quite diffculte to change?
There is no a simple toggle you can call from C# to change this option. However, you can use the following snippet by @Yury-Habets to set the Android window attributes directly. To adjust the setting at runtime, just call the SetRenderBehindNotch(bool enable)
method.
private const int CUTOUT_MODE_SHORT_EDGES = 1;
private const int CUTOUT_MODE_NEVER = 2;
private AndroidJavaObject m_Window;
private AndroidJavaObject m_Windowattributes;
public void SetRenderBehindNotch(bool enabled)
{
// Only run this method on Android devices
if (Application.platform != RuntimePlatform.Android)
return;
using(var version = new AndroidJavaClass("android.os.Build$VERSION"))
{
// Supported on Android 9 Pie (API 28) and later
if (version.GetStatic < int > ("SDK_INT") < 28)
{
return;
}
}
using(var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using(var activity = unityPlayer.GetStatic < AndroidJavaObject > ("currentActivity"))
{
m_Window = activity.Call < AndroidJavaObject > ("getWindow");
m_Windowattributes = m_Window.Call < AndroidJavaObject > ("getAttributes");
m_Windowattributes.Set("layoutInDisplayCutoutMode", enabled ? CUTOUT_MODE_SHORT_EDGES : CUTOUT_MODE_NEVER);
activity.Call("runOnUiThread", new AndroidJavaRunnable(ApplyAttributes));
}
}
}
void ApplyAttributes()
{
if (m_Window != null && m_Windowattributes != null)
m_Window.Call("setAttributes", m_Windowattributes);
}
This snippet has been extracted from github.com/Over17/UnityAndroidNotchSupport, visit this github project and check out the README if you want more info on how it works.