react-native-unity
react-native-unity copied to clipboard
The game is not playable from second launch
Hi @azesmway
I have embedded a Unity project (game) into my react native app. when the user taps on a button, the user is taken to a screen (stack navigation) where the game is playable. when the user exits the screen and comes back to play a second time without quiting the app, the game is not playable. I am facing the issue on both android and iOS that when the game screen is focused a second time, the game does open and the first scene is viewable and interactive. However when I want to play the game it becomes unresponsive, rest of my app works perfectly. The game works perfectly on both iOS and Android on the first launch. I suspect that the game needs some resources to load when the game is launched but is not getting it the second launch onwards.
I tried unloading the game when screen is out of focus, I see the game splash screen when I come back to the game screen but I don't see the "Made with unity" splash which is making me think the game is not unloading (quitting) completely.
I also tried quitting the game but that just quits/crashes my entire react native app.
My project specs: "@azesmway/react-native-unity": "^1.0.10", "react": "18.2.0", "react-native": "0.72.8", "@react-navigation/bottom-tabs": "^6.5.12", "@react-navigation/native": "^6.1.10", "@react-navigation/stack": "^6.3.21",
used unity version 2022.3.16
any help will be really appreciated
my unity screen
const unityRef = useRef<UnityView>(null);
const { goBack } = useNavigation<DefaultAppScreenNavigationProp>();
useEffect(() => {
const postMessage = {
authToken: 'abc_mock',
questId: '123_mock',
};
if (unityRef?.current) {
const message: IMessage = {
gameObject: 'ReactCommunicationManager',
methodName: 'OnReactMessageReceived',
message: JSON.stringify(postMessage),
};
unityRef.current.postMessage(message.gameObject, message.methodName, message.message);
}
}, []);
return (
<View style={styles.container}>
<UnityView
ref={unityRef}
style={styles.container}
onUnityMessage={(result) => {
console.log('onUnityMessage', result.nativeEvent.message);
// Alert.alert('onUnityMessage', result.nativeEvent.message);
}}
onPlayerUnload={(result) => {
console.log('onPlayerUnload', result.nativeEvent.message);
}}
onPlayerQuit={(result) => {
console.log('onPlayerQuit', result.nativeEvent.message);
goBack();
}}
fullScreen={true}
androidKeepPlayerMounted={false}
/>
</View>
)