Closed flowerhouse-dev closed 13 hours ago
Having the same issue with the demo app, it doesn't work in Android Landscape mode. It seems this issue is back? https://github.com/mob-sakai/SoftMaskForUGUI/issues/46 Would love to use this in Android Landscape mode, hope it'd be an easy fix... thank you @mob-sakai !
We made a workaround that disables the canvas for one frame after orientation change. Not ideal but it works for now.
I can confirm the bug. To reproduce it:
LoadSceneAsync
Awake
callback from a script that is part of the destination scene.On any devices, it almost always guaranteed to have the bug in soft mask. Sometimes I could reproduce it in the Editor on Simulator, but not as reliable as on a device.
If I reload the scene, not changing the orientation, then everything works fine. From debugging, I can see that soft mask handled screen orientation change, got rebuild everything after device created new frame buffer, with correct projection matrices. But for some reason image just doesn't show. I had everything logged frame by frame. I have a strong feeling that something just got cached and not updated somewhere in the script or shader parameters.
Unfortunately I was limited in time I can spare for debugging, so I had to go with a workaround. Simply disabling softmask if screen orientation happened and enabling it 10 frames later. With a smaller amount of frames there is a chance that softmask still not work. This workaround is ugly, but does the job.
Important thing to note. Initially I tired to force rebuild the mask, instead of disabling the script. Using hasChanhed
flag. It didn't work.
private ScreenOrientation _cachedOrientation;
private async void LateUpdate()
{
if (_cachedOrientation == Screen.orientation)
return;
enabled = false;
_cachedOrientation = Screen.orientation;
await UniTask.DelayFrame(10);
if (this == null)
return;
enabled = true;
}
Thank you for your reporting!
For everyone looking for a workaround. I've updated my solution, feel free to use it. Place the script on a static dedicated game object on a starting scene. Works just fine. It will affect only SoftMask components that were part of a scene when the scene was loaded and were enabled. I think 7 frames delay should be enough.
Keep in mind that this works only in case if screen orientation change happened after you have loaded the scene, in my case in do it in Awake
callback. Otherwise you will need to modify the script.
Also I'm using Unity 2023.1.3f1
internal class ScreenOrientationBugFixer : MonoBehaviour
{
private static bool _isInitialized;
private ScreenOrientation _cachedOrientation;
private void Awake()
{
if (_isInitialized)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
StartCoroutine(MonitorOrientationChange());
_isInitialized = true;
}
private IEnumerator MonitorOrientationChange()
{
_cachedOrientation = Screen.orientation;
var wait = new WaitForEndOfFrame();
while (true)
{
yield return wait;
if (_cachedOrientation == Screen.orientation)
continue;
_cachedOrientation = Screen.orientation;
StartCoroutine(FixSoftMasks());
}
}
private static IEnumerator FixSoftMasks()
{
var masks =
FindObjectsByType<SoftMask>(FindObjectsInactive.Exclude, FindObjectsSortMode.None)
.Where(m => m.enabled)
.ToArray();
masks.ForEach(m => m.enabled = false);
var wait = new WaitForEndOfFrame();
for (var i = 0; i < 7; i++)
yield return wait;
//It's not guaranteed that component still exists
masks.Where(m => m != null)
.ForEach(m => m.enabled = true);
}
}
Any plan to fix this the proper way please? @mob-sakai
Describe the bug Changing the screen orientation makes all SoftMasks disappear. Buffers seem to be updating correctly.
To Reproduce Make sure
Player Settings > Resolution and Presentation > Default Orientation
is set toAuto Rotation
In the editor:
On device:
Expected behavior SoftMasks should be updated similar to it updating when the resolution is changed.
Screenshots
Environment (please complete the following information):
Additional context Also tested with the changes from #151 but that does not fix it. Tried some workarounds with disabling & enabling the component, but that only works in the editor.