juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 505 forks source link

Unity calls screen rotation, white screen on iOS #887

Open kkrr6840 opened 8 months ago

kkrr6840 commented 8 months ago

Describe the bug Unity script call Screen. orientation=ScreenOrientation. LandscapeLeft; Rotate the screen, Invalid on iOS phone with white screen, normal on Android

To Reproduce Steps to reproduce the behavior: 1:In unity script create a button call Screen.orientation = ScreenOrientation.LandscapeLeft; 2:export ios(release) 3:running in flutter

Expected behavior A clear and concise description of what you expected to happen.

Screenshots IMG_0137

IMG_0138

Unity (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

maciej-szulc commented 8 months ago

Try giving some time after rotating the screen, f.e. 2 seconds and then call .resume() on unityWidgetController

Kiruthika2206 commented 5 months ago

Hi,

I'm getting this same white screen issue when using Screen. orientation=ScreenOrientation. LandscapeLeft; in IOS.

And I have called .resume() method in unityWidgetController also. It is not working.

Is there any other solution to fix this issue?

timbotimbo commented 5 months ago

Can any of you share details like Unity version and Flutter version?
I think I skipped this one earlier because crucial data like that was missing.

Please try using the latest Unity 2021 or 2022 version and report back.

Some unity versions have a lot of bugs in iOS screen rotation. For example the 2021.3.28 changelog contains 3 separate messages for rotation fixes. And checking others, it is far from the only one.

Kiruthika2206 commented 5 months ago

Hi @timbotimbo

I'm using this, Unity version : 2021.3.11f1 Flutter version : 3.3.10

When generating build from Unity iOS module, orientation is working fine.

But when generating iOS build after integrating unity with flutter, I'm getting white screen issue.

Kiruthika2206 commented 5 months ago

Hi @timbotimbo

I'm facing this issue in my current project. If you provide any solution for this, it'll be very useful for us.

maciej-szulc commented 5 months ago

@Kiruthika2206 For us giving two second time in onUnityCreated and then calling .resume() worked. Future<void> onUnityCreated(UnityWidgetController controller) async { await Future.delayed(Duration(milliseconds: 2000)); await _unityWidgetController.resume(); ...

Kiruthika2206 commented 5 months ago

Hi @maciej-szulc

I have added the code provided by you in my project. But still I'm getting white screen.

I have added one button action in unity. When user clicks on that button Screen. orientation=ScreenOrientation.AutoRotation; this code will trigger. On that time we are getting white screen in iOS.

maciej-szulc commented 5 months ago

@Kiruthika2206 I understand that when you change the screen orientation, you also rebuild the entire widget in Flutter that contains FlutterUnityWidget?

Kiruthika2206 commented 5 months ago

@maciej-szulc Yes widget is rebuilding when change orientation button action triggered.

emileswain commented 3 months ago

Just wanted to confirm that we encountered the same issue embedding the Lightship example project https://github.com/niantic-lightship/ardk-samples/ into our flutter app for testing the various ARDKs etc.

On first load the main menu scene would appear white. If we changed the build order to load any of the others scenes first, everything worked fine.

if we loaded another scene after gettting the white screen, everything worked ok.

We found that in https://github.com/niantic-lightship/ardk-samples/blob/ff7a7f20817a71b1d4f9bb5fe8176a5f17f274e1/Assets/Samples/Common/Scripts/VersionRead.cs#L15 they have the line ...

void Awake(){
        Screen.orientation = ScreenOrientation.Portrait;
    }

god knows why they have this in VersionRead.cs

Removing this offending line made everything work ticketyboo. I haven't checked to see if having this line somewhere else, in combinatino with the delayed resume() code as suggested makes any difference. I'll be sure to post if we come across this issue again. Needless to say, our issue was moreover someone adding spurios code to completely unrelated scripts. VersionRead does not need to call screen orientation ffs.