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

Screen freezes when opening UnityView two times #75

Open
Arnaod opened this issue Dec 14, 2021 · 7 comments · Fixed by blackfoot-makers/react-native-unity-view#1
Open

Comments

@Arnaod
Copy link

Arnaod commented Dec 14, 2021

Hi everyone,

I'm getting an head scratching bug for a few days.

My react-native app uses the unityView at several places. I can open it at every place without issues, but when I'm trying to open it two times in a row (either at the same place or different places), the screen freezes.

The screen displays the last frame that unity rendered before closing Unity.

The strangest thing is that the unityView is still running : I can ear the sounds and even click on buttons (if I remember where they are 😄)

The issue looks similar to open issues in the former module like this one for instance .

The former fix seemed to be this, but doesn't work here.

<UnityView style={{ position: 'absolute', left: 0, right: 0, top: 1, bottom: 1 }} />

Relevant code for the modal on RN side :

`class UnityModalComponent extends Component {
constructor(props) {
super(props);
const { route } = props;
this.state = {
renderUnity: true,
currentScene: route.params?.data?.scene,
};
this.shouldWait = false;
}

componentDidMount() {
const { currentScene } = this.state;
StatusBar.setHidden(true);
UnityModule.isReady().then(ready => {
if (ready) {
this.shouldWait = false;
UnityModule.postMessageToUnityManager(currentScene);
} else {
this.shouldWait = true;
}
});
}

componentDidUpdate(prevProps, prevState) {
const { renderUnity } = this.state;
if (renderUnity !== prevState.renderUnity && !renderUnity) {
const { navigation } = this.props;
navigation.pop();
}
}

componentWillUnmount() {
StatusBar.setHidden(false);
}

Did anyone encounter the issue or has any idea on how to fix this?

Thank you,

@IbrahimaWane
Copy link

I encountered the same issue when I was building on Android and I had to change the source code. The issue happens when the window is being detached and reattached.
To solve it go to node_modules/@admadsen/android/src/main/java/no/asmadsen/unity/view and open UnityUtils.java and add this method:

public static void removeUnityView(){
        if (unityPlayer == null) {
            return;
        }
        final Activity activity = ((Activity) unityPlayer.getContext());
        activity.startActivity(activity.getIntent());
    }

Now open UnityView.java and call it here:

@Override
    protected void onDetachedFromWindow() {
        UnityUtils.removeUnityView();
        super.onDetachedFromWindow();
    }

@Arnaod
Copy link
Author

Arnaod commented Dec 15, 2021

It really seemed like it could work for us @IbrahimaWane but sadly this does not fix the issue, thanks anyway.
@NeelSteampunkDigital for us the issue is a little different: we don't have this message in the react native console, also even if we try to load a new scene we still have the issue

@IbrahimaWane
Copy link

It's unfortunate because the issue you described is exactly the same one I encountered. Try to use Android Studio Logcat to see the error message. Because mine also was not shown in the react native console. Good luck

@IbrahimaWane
Copy link

I forgot to mention, try to call UnityModule.createUnity() before rendering UnityView

@Arnaod
Copy link
Author

Arnaod commented Dec 17, 2021

Thank you @IbrahimaWane, unfortunately it didn't work on my issue.

I just realised that when the screen is black, if I lock the phone and switch back to the app, it works. Something to dig there probably.

@Arnaod
Copy link
Author

Arnaod commented Jan 5, 2022

Hey @asmadsen,

We're really stuck on this issue for quite some time and can't seem to figure it out.
Would you be open to some freelancing to help us dig into the issue ?
Thanks and happy new year !

thingthing pushed a commit to blackfoot-makers/react-native-unity-view that referenced this issue Feb 14, 2022
@sael-you
Copy link

sael-you commented Feb 9, 2024

Hey @Arnaod it have exactly same issue on android 13+, have you been able to solve the issue ? i know it's been a while, but a yes or no might just gi ve me hope if you don't remember the how you fixed it if you fixed it.

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