azesmway / react-native-unity

MIT License
261 stars 61 forks source link

onUnityMessage not working on v0.2.0, message don't response #24

Open salamtamp opened 2 years ago

salamtamp commented 2 years ago

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.

Screen Shot 2565-06-03 at 16 33 14

Anyone have idea for this case

azesmway commented 2 years ago

This example https://github.com/azesmway/react-native-unity/tree/main/example

There is no such thing in the plugin - <UnityViewForIOS>

salamtamp commented 2 years ago

@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.

GunnarMM commented 2 years ago

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...

GunnarMM commented 2 years ago

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?