flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
Unity screen is white after scene load (iOS)
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
@juicycleff bump with the same issue, any ideas or workarounds?
@juicycleff any info?
I noticed this issue myself on Android sadly today. I guess something has changed the behavior and I will resolve it
@juicycleff I notice this error after call method with changing scene (which would send to unity to display specific scene).
@dawiddszewczyk your right. Will debug and and create a patch. I need it for a project so I will get it done asap
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.
@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.
There is another way to fix it. Just call unityController.resume()
after you get white screen. It also helps.
@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
@juicycleff Hey, need some info asap, should we investigate it on our own as well?
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 ok, please send some info where should we look for a bug anyway if you couldn't push all changes
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.
@juicycleff it's any solution to resolve that bug :/ ??
Test sorry for taking long on this, tested it again and couldn't replicate the issue. On iOS and Android anymore
@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.
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 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