react-native-unity
react-native-unity copied to clipboard
onUnityMessage not working on v0.2.0, message don't response
I try to use onUnityMessage from lib version 0.2.0 but it doesn't work, message don't response when I call to action from unity.

Anyone have idea for this case
This example https://github.com/azesmway/react-native-unity/tree/main/example
There is no such thing in the plugin - <UnityViewForIOS>
@azesmway I just wrong typo that I renamed to test IOS.
this my code
const AndriodUnityView = (
<View style={{ flex: 1 }}>
<UnityView
fullScreen={true}
style={{ flex: 1 }}
onUnityMessage={(obj: any) => {
console.log('[Screen] onUnityMessage')
console.log(obj.nativeEvent.message)
}}
/>
</View>
)
I followed the code from your example.
I am experiencing a similar issue.
I am seeing messages come in through the XCode log console, but self.onUnityMessage
is null whenever I try to open the UnityView in one particular place (let's call this "Gallery").
In another place in my app (alias "AR") I have this same UnityView being opened and it does not cause self.onUnityMessage
to be null...?
The message I am waiting on is a custom UNITY_READY message and the app is not sending any data until it receives this message.
I can see in my logs that sendMessageToMobileApp
is being executed every time a message comes in from Unity.
- (void)sendMessageToMobileApp:(NSString *)message {
NSLog(@"self.onUnityMessage: %@", self.onUnityMessage);
if (self.onUnityMessage) {
NSDictionary* data = @{
@"message": message
};
self.onUnityMessage(data);
}
}
self
is not null, but self.onUnityMessage
almost always is on "Gallery".
'almost' because sometimes on app start I'm able to receive UNITY_READY when opening "Gallery", but the second time in the same session I'll lose self.onUnityMessage
...
I have made a change to the Unity build where it will ping the UNITY_READY message for a few seconds. This causes the first message to fail, but at least self.onUnityMessage
is re-initialized again, so the second UNITY_READY message is forwarded to RN !
Anyone have a guess what is going wrong here?