Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to close Unity Game (UnityView) #9

Open
Vaibhaw-Redapple opened this issue Jul 10, 2020 · 12 comments
Open

How to close Unity Game (UnityView) #9

Vaibhaw-Redapple opened this issue Jul 10, 2020 · 12 comments

Comments

@Vaibhaw-Redapple
Copy link

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 Vaibhaw-Redapple changed the title How close Unity Game (UnityView) How to close Unity Game (UnityView) Jul 10, 2020
@rakirox
Copy link

rakirox commented Jul 21, 2020

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

@asmadsen
Copy link
Owner

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

@rakirox
Copy link

rakirox commented Jul 24, 2020

@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.

@paulfreund94
Copy link

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

@Apetrou
Copy link

Apetrou commented Aug 11, 2020

@rakirox do you mind sharing how you achieved that?

@rakirox
Copy link

rakirox commented Aug 11, 2020

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

@Apetrou
Copy link

Apetrou commented Aug 11, 2020

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

@rakirox
Copy link

rakirox commented Aug 12, 2020

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

@nguyendarryl
Copy link

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

@zoix
Copy link

zoix commented Jan 31, 2021

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.

@gambit19
Copy link

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

@DavidCotovanu
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants