flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Unity screen is white after scene load (iOS)

Open dawiddszewczyk opened this issue 1 year ago • 16 comments

Describe the bug I have two unity scenes, Loading and Second one. The loading scene works well. I can see it, but when this scene switches to another one, the screen is white after the scene is loaded (it's just the app background). It looks like the scene is behind this white screen. This error is only on iOS on Android, everything works well.

I saw resolve issue Link But in this way, when I will pop the screen than Flutter App is like blocked I can't press anything there(like a button), and also, hot-reload doesn't unblock the app. It seems like unity still has control of the app.

Also its very similar with this bug

Unity (please complete the following information):

  • OS: iOS
  • Version 15.5
  • Editor Version 2021.1.24f1

Smartphone (please complete the following information):

  • Device: iPhone SE
  • OS: iOS
  • Version 15.5

dawiddszewczyk avatar Jul 08 '22 21:07 dawiddszewczyk

@juicycleff bump with the same issue, any ideas or workarounds?

kaczmarzk avatar Aug 06 '22 15:08 kaczmarzk

@juicycleff any info?

maciej-szulc avatar Aug 11 '22 15:08 maciej-szulc

I noticed this issue myself on Android sadly today. I guess something has changed the behavior and I will resolve it

juicycleff avatar Aug 11 '22 16:08 juicycleff

@juicycleff I notice this error after call method with changing scene (which would send to unity to display specific scene).

dawiddszewczyk avatar Aug 11 '22 20:08 dawiddszewczyk

@dawiddszewczyk your right. Will debug and and create a patch. I need it for a project so I will get it done asap

juicycleff avatar Aug 11 '22 21:08 juicycleff

I also had the same problem. After scene loaded and made it active I called this: Screen.orientation = ScreenOrientation.AutoRotation; And it makes scene screen white on iOS. Just commented it and now it works fine.

artemsivcev avatar Aug 13 '22 13:08 artemsivcev

@juicycleff hey, any progress? I will need to build a release for iOS in the near future and am wondering what my options are here.

maciej-szulc avatar Aug 17 '22 10:08 maciej-szulc

There is another way to fix it. Just call unityController.resume() after you get white screen. It also helps.

artemsivcev avatar Aug 17 '22 10:08 artemsivcev

@artemsivcev I try this way but this bug still exist there :/ Like use pause for 1s and resume for 1s option on controller to refresh

dawiddszewczyk avatar Aug 17 '22 13:08 dawiddszewczyk

@juicycleff Hey, need some info asap, should we investigate it on our own as well?

maciej-szulc avatar Aug 23 '22 11:08 maciej-szulc

Fell I'll had to take a pause. But feeling much better and looking into it. Mind you this only happens with flutter 3

juicycleff avatar Aug 23 '22 11:08 juicycleff

@juicycleff ok, please send some info where should we look for a bug anyway if you couldn't push all changes

maciej-szulc avatar Aug 24 '22 13:08 maciej-szulc

There is another way to fix it. Just call unityController.resume() after you get white screen. It also helps.

In my case, I was getting a white screen when Ios changes its orientation. Calling unityController.resume() after changing orientation fixed issue.

ritheshSalyan avatar Aug 26 '22 09:08 ritheshSalyan

@juicycleff it's any solution to resolve that bug :/ ??

dawiddszewczyk avatar Sep 01 '22 15:09 dawiddszewczyk

Test sorry for taking long on this, tested it again and couldn't replicate the issue. On iOS and Android anymore

juicycleff avatar Sep 01 '22 15:09 juicycleff

@juicycleff Did you see the recorded screen sent by @dawiddszewczyk ? This happens each time on iOS when you send a scene change command to Unity. On Android works well.

maciej-szulc avatar Sep 01 '22 16:09 maciej-szulc

I was able to fix this by adding a manual unload and reload. Here is the code I'm using to solve this:

UnityWidgetController? _unityWidgetController;
  Timer? timer;
  bool _isCheckingLoadState = false;
  bool _hasBeenRestarted = false;

  void _onUnityCreated(UnityWidgetController controller) async {
    _unityWidgetController = controller;
    // Due to an issue with the Unity plugin when it sometimes fails to load the
    // Unity scene, we perform a reload after the first unity scene creation. It
    // ensures that (1) the scene is loaded correctly and (2) the scene restarts
    // after a flutter restart during debugging.
    if (!_hasBeenRestarted) {
      _hasBeenRestarted = true;
      await _reloadUnityScene();
    }
  }

  Future<void> _reloadUnityScene() async {
    await _unityWidgetController?.unload();
    timer = Timer.periodic(
      const Duration(milliseconds: 500),
      (_) async {
        if (!_isCheckingLoadState) {
          _isCheckingLoadState = true;
          final isLoaded = await _unityWidgetController?.isLoaded() ?? false;
          if (!isLoaded) {
            timer?.cancel();
            await _unityWidgetController?.create();
          }
          _isCheckingLoadState = false;
        }
      },
    );
  }

Please note that, at the moment, I'm getting an exception when calling the create method. I have filed an issue regarding this, which I hope to get resolved soon. The fix works as expected, though.

behnamsattar avatar Nov 04 '22 19:11 behnamsattar

@behnamsattar it seems like I've been able to fix it for now by just calling resume on the controller:

Future<void> _onUnityCreated(UnityWidgetController controller) async {
    _unityWidgetController = controller;
    if (!_hasBeenRestarted) {
      _hasBeenRestarted = true;
      await _unityWidgetController.resume();
    }
  }

I didn't use the _reloadUnityScene() method

rickdijk avatar Jan 21 '23 11:01 rickdijk