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.13k stars 518 forks source link

quit and unload methods not Implemented #862

Open codesculpture opened 1 year ago

codesculpture commented 1 year ago

If i try to invoke unityWidgetController.quit() or unityWidgetController.unload() am getting Missing Implementation Error

timbotimbo commented 1 year ago

Which platform is this (ios, android, web)? And how/where are you calling these functions?

Quit is useless as it kills your entire app, but i've used unload plenty of times.

codesculpture commented 1 year ago

Iam trying this on Android, and am calling the unityController.unload() at app's dispose (stateful widget) method. I can see that game is never closes like once i opened the game and no matter how many time i pop this page and come again and the game still in the same state where i last time leaves on pop Method

codesculpture commented 1 year ago

Also when i open the game it would make disappear the android's navigation bar and status bar and it not restored when the game end, can anyone help this.. i tried many ways but none of em working

timbotimbo commented 1 year ago

Iam trying this on Android, and am calling the unityController.unload() at app's dispose (stateful widget) method. I can see that game is never closes like once i opened the game and no matter how many time i pop this page and come again and the game still in the same state where i last time leaves on pop Method

I think this error might come from using the unitycontroller when the widget has already been disposed. Can you try calling unload before popping. Either do it before Navigator.of(context).pop, or in a WillPopScope.

Also when i open the game it would make disappear the android's navigation bar and status bar and it not restored when the game end, can anyone help this.. i tried many ways but none of em working

Once Unity goes fullscreen, flutter can't seem to revert that on android. You can do this by calling a Unity function from flutter, that makes Unity disable fullscreen.

    public void DisableFullscreen(string str = "")
    {
#if UNITY_ANDROID
        Screen.fullScreen = false;
#endif
    }
codesculpture commented 1 year ago

Hey also, i passed unLoadonDispose to be true on UnityWidget, but i dont think it is working either. I needed that game is to be totally closed when the page is closed from flutter. And the game should reload again after when i opened the game page... But it seems the game is being always loaded.. like if i open the game page for first time it would take some time to load and shows the game . But after i close the game page and repopen the game page the game is already in the same state where i lastly visited the game page. I dont want this behavior

alexandrefresnais commented 1 year ago

I am impacted too on iOS. Calling unload in a dispose method does not unload unity at all. It was working fine in 2020.3.25 unloadOnDispose does not work neither.

konsnos commented 1 month ago

Same here as well. Tried only iOS. Using version 2022.2.0 and Unity 2022.3.34. Tried manual unload and unloadOnDispose and didn't work.

codesculpture commented 1 month ago

Bumping up this thread, i literally dint touched flutter (and unity) almost a year. But happy to help. I think we should not call quit as @timbotimbo said since it would just kill the process (where our flutter app also lives in the same process, hence it will also get closed)

https://discussions.unity.com/t/integration-unity-as-a-library-in-native-android-app/744894/5

Someone here explained what i want to just convey, the implementation of quit on UnityPlayer in unity-classes.jar which eventually kill the process. We dont need that, we just need to destroy the unity activity and its memory. I think in the discussion someone mentioned "we are working on it"

Hope for good 🤞