Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to restart Unity Player Android

Discussion in 'Android' started by GemmaLamont, Oct 11, 2018.

  1. GemmaLamont

    GemmaLamont

    Joined:
    Oct 9, 2018
    Posts:
    8
    I have an app which in an activity opens with a subview containing UnityPlayer. This works well and as expected.

    Next, I open a fragment which also contains a a subview with a UnityPlayer. This subview also works.

    Problem is, when this fragment is closed, the activities subview shows a frozen image of the scene and will eventually crash. I am unsure how to continue, has anyone managed to pass the UnityPlayer between fragments or kept an alive instance or any other idea for this?
     
  2. JC-Cimetiere

    JC-Cimetiere

    Unity Technologies

    Joined:
    May 8, 2014
    Posts:
    123
    Hello,
    Unity Player is not designed to be loaded by a native app, we don't support this scenario, so whatever trick you are using to workaround might lead to unstable behavior.
    However, we'd be interested to learn more about your scenario, feel free to explain more here or send me a private message.
    JC
     
  3. GemmaLamont

    GemmaLamont

    Joined:
    Oct 9, 2018
    Posts:
    8
    I managed to get this to work by using a singleton containing the UnityPlayer and then making sure that the onStop() and onDestroy() methods only get called when the activity isFinishing(). Then when going from Activity to fragment I can just reuse the same UnityPlayer (trick is to detach the parent views first :) ).

    This works well as the context isn't changing as it is the same activity. I tried to apply the same logic to onOrientationChange() where the view gets destroyed and recreated. However, onOrientationChange() creates a new context each time and this means the singleton UnityPlayer (while appearing to work as all message calls are static) is still retaining the old context. I can't find a work around for this, as my only option to change context seems to be to create a new Unity Player which then breaks everything.

    Any ideas on how to do this?
     
    Cluchao and MarcSpraragen like this.
  4. MarcSpraragen

    MarcSpraragen

    Joined:
    Jun 29, 2020
    Posts:
    8
    4 years later, this is the *only* approach I've tried that works for Unity player reuse (the multiprocess + sockets may work, but I never tried it: https://forum.unity.com/threads/how-to-exit-unityplayeractivity-not-to-kill-whole-process.546619/ ).

    I haven't needed to test orientation change => auto new context with respect to Unity player reuse. Did you ever find a solution to that one?
     
    Cluchao likes this.