react-native-unity-view icon indicating copy to clipboard operation
react-native-unity-view copied to clipboard

How to close Unity Game (UnityView)

Open Vaibhaw-Redapple opened this issue 4 years ago • 12 comments

In React Native App at some page i have loaded UnityView. After exiting from that page, when user visits again that page then can we start the unity once again not resuming. As of now it keeps running until app is killed from memory. Means on page exit can unity be destroyed ?

Vaibhaw-Redapple avatar Jul 10 '20 11:07 Vaibhaw-Redapple

Hi @Vaibhaw-Redapple , I don´t know if there is some one maintaining this code (there are some interesting pr which I would like to merge). But this particular Issue is on my path I'll check it out and change the way it works or at least I'll make a method which destroys the unity instance. but it might take some time (my to do list is huge)

to @asmadsen I would be happy to help you out maintaining this project. I'll be actively using it for a while I don't like the idea of having many forks with some small fixes. I think all effort should be in one place

rakirox avatar Jul 21 '20 20:07 rakirox

Hi, @rakirox I'm no longer maintain this repo. However I'm happy to merge any pr with fixed as long as it doesn't break existing features

asmadsen avatar Jul 21 '20 20:07 asmadsen

@Vaibhaw-Redapple Just a heads up, i just solved this issue on android. In the next days I'll check it out for iOS.

It will release must of unity memory usage and unload all scenes but it will keep in memory enough things to make a faster init the next time.

rakirox avatar Jul 24 '20 02:07 rakirox

@rakirox any chance you could share how you've gone about it / maybe open a PR?

paulfreund94 avatar Aug 05 '20 17:08 paulfreund94

@rakirox do you mind sharing how you achieved that?

Apetrou avatar Aug 11 '20 13:08 Apetrou

Yes! sorry been busy. tonight I'll draft a PR. I fixed only for android but haven't test it with iOS

rakirox avatar Aug 11 '20 14:08 rakirox

Thanks so much @rakirox! Been trying a few things using native code but I keep killing the whole app!

Apetrou avatar Aug 11 '20 14:08 Apetrou

People, I just draft a PR which attack this problem for Android so you can use it before it's ready.

I hope this weekend I'll have time to resolve al pending points.

cc: @Apetrou @paulfreund94 @Vaibhaw-Redapple Draft Pull Request

rakirox avatar Aug 12 '20 22:08 rakirox

@rakirox Thank you for this! Any luck with iOS?

nguyendarryl avatar Jan 19 '21 05:01 nguyendarryl

We solved this by just loading and unloading the main scene with postMessageToUnityManager:

void MessageHandler(string message)
    {
        Debug.Log("onMessage: " + message);
        if (message == "start")
        {
            SceneManager.LoadScene("AR", LoadSceneMode.Additive);
        } else if (message == "stop")
        {
            SceneManager.UnloadSceneAsync("AR");
        }
    }

Not the most elegant solution but it works.

zoix avatar Jan 31 '21 20:01 zoix

Hi @asmadsen @rakirox Did you figure out a way to completely exit the Unity module on both Android and iOS? Thanks!

gambit19 avatar Oct 13 '21 07:10 gambit19

Hi @asmadsen @rakirox Did you figure out a way to completely exit the Unity module on both Android and iOS? Thanks!

Same idea with the MessageHandler from @agamadev answer, but you call Application.Quit() instead of SceneManager.UnloadSceneAsync("AR"). This will close the Unity app entirely.

DavidCotovanu avatar Dec 21 '21 07:12 DavidCotovanu