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

unloadUnity() no work

Open iamjessroman opened this issue 3 years ago • 22 comments

Hello,

When opening the unity module for the first time there is no problem, but when reopening show the previous state, not restart.

To close UNITY I use:

         unityRef.current.unloadUnity();
         navigation.goBack();

But it continues to save the previous state, that is, I open a SCENE X on Unity for the first time, I close and then reopen Unity to open a SCENE Y and it continues to show the SCENE X.

Then I try again to open the SCENE Y and there it already shows the SCENE Y, but if I continue playing when showing the SCENE X again it shows me SCENE Y again and so on.

iamjessroman avatar Aug 14 '22 18:08 iamjessroman

Hello, I have the same issue when I go back to react-native scene and go again to my unity view it crashes the app and I noticed that it doesn't continue from its previous state it's like it launches the unity again so maybe it crashes from low memory. if any one have any related ideas could use unload or anything else thank you.

st3pa avatar Aug 15 '22 16:08 st3pa

Hello, I have a similar issue as well.

I unload the unity and go back

 navigation.goBack();

Next time when I open the unity view I get only a blank screen. The unity game does not launch.

When the unload function is called I get this error in the logcat

2022-08-30 12:24:24.184 16354-19822/com.android.myfab11pro I/Unity: Back button called
    UnityEngine.Events.UnityAction:Invoke()
    UnityEngine.Events.UnityEvent:Invoke()
    UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    UnityEngine.EventSystems.StandaloneInputModule:Process()
     
    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
2022-08-30 12:24:24.292 16354-16354/com.android.myfab11pro I/ReactNative: [GESTURE HANDLER] Gesture handler is already enabled for a parent view
2022-08-30 12:24:24.303 16354-19866/com.android.myfab11pro E/Unity: ThreadAbortException
      at SocketIO.SocketIOComponent.RunSocketThread (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
    System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
     
    (Filename: currently not available on il2cpp Line: -1)
2022-08-30 12:24:24.304 16354-19868/com.android.myfab11pro E/Unity: ThreadAbortException
      at SocketIO.SocketIOComponent.RunPingThread (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
    System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
     
    (Filename: currently not available on il2cpp Line: -1)
When I go back to the unity view screen I get this error in the logcat
2022-08-30 12:26:35.524 16354-19822/com.android.myfab11pro D/AudioTrack: ClientUid 10558 AudioTrack::start 
2022-08-30 12:26:35.529 16354-16354/com.android.myfab11pro V/MediaRouter: Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
2022-08-30 12:26:35.546 16354-20430/com.android.myfab11pro E/Unity: ThreadAbortException
      at SocketIO.SocketIOComponent.RunPingThread (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
    System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
     
    (Filename: currently not available on il2cpp Line: -1)
2022-08-30 12:26:35.576 16354-20429/com.android.myfab11pro E/Unity: ThreadAbortException
      at SocketIO.SocketIOComponent.RunSocketThread (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0 
    System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
     
    (Filename: currently not available on il2cpp Line: -1)
2022-08-30 12:26:35.581 16354-19822/com.android.myfab11pro D/roid.myfab11pr: PlayerBase::stop() from IPlayer
2022-08-30 12:26:35.581 16354-19822/com.android.myfab11pro D/AudioTrack: ClientUid 10558 AudioTrack::stop 
2022-08-30 12:26:35.581 16354-19822/com.android.myfab11pro D/AudioTrack: stop(14365): called with 1924 frames delivered

rtndeep9 avatar Aug 30 '22 05:08 rtndeep9

@azesmway we are facing the same issue. here are our environment details: Windows 10 Pro Android Studio Chipmunk - 2021.2.1 React Native 0.70.0 Unity Editor Version 2021.3.9f1

hoping to get some help soon.

psbdgr8 avatar Sep 09 '22 11:09 psbdgr8

I'm facing the same issue :( Hi, @azesmway you have any solutions for this?

vahtykov avatar Sep 18 '22 20:09 vahtykov

Any solution to this?

daniel-keen avatar Sep 22 '22 11:09 daniel-keen

getting the same issues

harrymash2006 avatar Oct 14 '22 17:10 harrymash2006

Hello,

When opening the unity module for the first time there is no problem, but when reopening show the previous state, not restart.

To close UNITY I use:

         unityRef.current.unloadUnity();
         navigation.goBack();

But it continues to save the previous state, that is, I open a SCENE X on Unity for the first time, I close and then reopen Unity to open a SCENE Y and it continues to show the SCENE X.

Then I try again to open the SCENE Y and there it already shows the SCENE Y, but if I continue playing when showing the SCENE X again it shows me SCENE Y again and so on.

Did you find any solution?

ambojialur avatar Oct 20 '22 06:10 ambojialur

I am getting the same issue!

ambojialur avatar Oct 20 '22 06:10 ambojialur

the plugin only starts the unit itself and then unloads it from memory using the documented Unity functions. manage scene restarts in Unity itself - you should handle events using only Unity itself

azesmway avatar Oct 20 '22 06:10 azesmway

the plugin only starts the unit itself and then unloads it from memory using the documented Unity functions. manage scene restarts in Unity itself - you should handle events using only Unity itself

can you please provide an sample code for that, Thank you

ambojialur avatar Oct 20 '22 12:10 ambojialur

I am a RN developer Unity I know only at the assembly level of the project

azesmway avatar Oct 20 '22 12:10 azesmway

For me the application is crashing as in the attached video - https://user-images.githubusercontent.com/22703602/167987171-13875d0e-8b25-4625-bc25-299569d4e7b9.mp4

ambojialur avatar Oct 20 '22 12:10 ambojialur

@azesmway I resolved the issue by NOT calling unloadUnity, but if I do navigation back and then come to the screen with unityview it crashes/freezes without starting unity again and this happens on a few devices only, on another device it works fine. any idea ?

harrymash2006 avatar Oct 20 '22 16:10 harrymash2006

@harrymash2006 I am also facing the same issue, on which device it's working fine? I am using S8.

ambojialur avatar Oct 20 '22 19:10 ambojialur

@azesmway I resolved the issue by NOT calling unloadUnity, but if I do navigation back and then come to the screen with unityview it crashes/freezes without starting unity again and this happens on a few devices only, on another device it works fine. any idea ?

@harrymash2006 How did you fix crashing on the navigation back?

ambojialur avatar Oct 20 '22 19:10 ambojialur

@ambojialur I just do not call unloadUnity function and it stops crashing

harrymash2006 avatar Oct 20 '22 19:10 harrymash2006

@ambojialur I just do not call unloadUnity function and it stops crashing

Can you please share your code if possible, Thank you

ambojialur avatar Oct 21 '22 05:10 ambojialur

If unloadUnity () is not called the app will not crash but then the game would keep running in the background. This can cause issues like unnecessary sounds and consuming too much memory.

So I modified the library as done in the fork. Then unloadUnity () wont be called automatically when going back but calling it manually then does solve the problem.

Karrthik-Arya avatar Oct 21 '22 09:10 Karrthik-Arya

@Karrthik-Arya It's not crashing now, The issue is when navigating back from the unity view and reopening the unity view it's not relaunching the unity view. it's just showing the previously opened view.

ambojialur avatar Oct 21 '22 12:10 ambojialur

@azesmway Can you please help me that why app is crashing after getting below message

2022-10-24 /com.example W/Unity: Timeout while trying detaching primary window.
2022-10-24 /com.example E/CRASH: other thread is trapped; signum = 11
2022-10-24 /com.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example, PID: 123
    java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    Version '2021.3.11f1 (asdf)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a'
    Build fingerprint: 'mobiledevice/dreamltexx/dreamlte:9/PPR1.180610.011/ASDF09876:user/release-keys'
    Revision: '10'
    ABI: 'arm64'
    Timestamp: 2022-10-24 16:53:25+123
    pid: 123, tid: 123, name: Thread-11  >>> com.example <<<
    uid: 123
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x44
    Cause: null pointer dereference
        x0  0000000000000000  x1  0000006e59afed38  x2  0000006e59afed44  x3  0000000000000002
     

ambojialur avatar Oct 24 '22 11:10 ambojialur

@Karrthik-Arya, thx. work for me.

ssdenis00 avatar Oct 26 '22 12:10 ssdenis00

Hello , has anyone found a solution with unloadUnity() and Black screen ? currently Im using @azesmway/react-native-unity": "^1.0.5

KarimScript avatar Nov 28 '23 12:11 KarimScript