react-native-unity-view
react-native-unity-view copied to clipboard
How to close Unity Game (UnityView)
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 ?
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
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
@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 any chance you could share how you've gone about it / maybe open a PR?
@rakirox do you mind sharing how you achieved that?
Yes! sorry been busy. tonight I'll draft a PR. I fixed only for android but haven't test it with iOS
Thanks so much @rakirox! Been trying a few things using native code but I keep killing the whole app!
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 Thank you for this! Any luck with iOS?
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.
Hi @asmadsen @rakirox Did you figure out a way to completely exit the Unity module on both Android and iOS? Thanks!
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.