flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Can not return back to flutter from unity Android

Open Somshekardsi opened this issue 3 years ago • 2 comments

Can not return back to flutter from unity and unload unity not working.

overrideActivity is null var jc = new AndroidJavaClass("com.xraph.plugin.flutter_unity_widget.OverrideUnityActivity"); var overrideActivity = jc.GetStatic<AndroidJavaObject>("instance"); overrideActivity.Call("showMainActivity"); 20210703_185211

I/Unity (19112): Object reference not set to an instance of an object. I/Unity (19112): UnityEngine.Events.UnityAction:Invoke() I/Unity (19112): UnityEngine.Events.UnityEvent:Invoke() I/Unity (19112): UnityEngine.EventSystems.EventFunction1:Invoke(T1, BaseEventData) I/Unity (19112): UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1) I/Unity (19112): UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) I/Unity (19112): UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() I/Unity (19112): UnityEngine.EventSystems.StandaloneInputModule:Process() I/Unity (19112):
I/Unity (19112): (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 39)

Somshekardsi avatar Jul 03 '21 13:07 Somshekardsi

Same issue here on android, did you get it to work in the end?

ROBYER1 avatar Sep 10 '21 09:09 ROBYER1

I also get this error when running the example project. Easy to reproduce: just run the example, tap on LOAD NATIVE SCENE, then tap UNLOAD or GO BACK.

I/Unity (21011): Object reference not set to an instance of an object. I/Unity (21011): UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) I/Unity (21011): UnityEngine.Logger:Log(LogType, Object) I/Unity (21011): UnityEngine.Debug:Log(Object) I/Unity (21011): FlutterUnityIntegration.NativeAPI:UnloadMainWindow() (at C:\Users\james\GithubRepos\flutter-unity-view-widget\example\unity\DemoApp\Assets\FlutterUnityIntegration\NativeAPI.cs:93) I/Unity (21011): FlutterUnityIntegration.UnityMessageManager:UnloadMainWindow() (at C:\Users\james\GithubRepos\flutter-unity-view-widget\example\unity\DemoApp\Assets\FlutterUnityIntegration\UnityMessageManager.cs:100) I/Unity (21011): SceneLoader:UnloadNative() (at C:\Users\james\GithubRepos\flutter-unity-view-widget\example\unity\DemoApp\Assets\FlutterUnityIntegration\Demo\SceneLoader.cs:40)

So the problem is a null reference exception in NativeAPI.cs here:

        try
        {
            var jc = new AndroidJavaClass("com.xraph.plugin.flutter_unity_widget.OverrideUnityActivity");
            var overrideActivity = jc.GetStatic<AndroidJavaObject>("instance");
            overrideActivity.Call("showMainActivity");
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }

I'm not sure why this happens. Also not sure what 'Native Scene' even means. @juicycleff can you explain what the Native Scene in the demo is? How is it different to the normal scene / what makes it 'native'? Looking at the code I can't figure out why it exists or what it's demoing. Also, any idea why navigating back from the native scene causes this null exception?

This is also a duplicate of #635

jamesncl avatar Aug 09 '23 15:08 jamesncl