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

onUnityMessage/onMessage stops receiving messages dispatched by Unity after Metro refresh #41

Open
dave-vazquez opened this issue Apr 19, 2021 · 2 comments

Comments

@dave-vazquez
Copy link

dave-vazquez commented Apr 19, 2021

@asmadsen

I'm running into an issue where when I refresh the Metro server, UnityView's onUnityMessage and onMessage handlers stop receiving messages dispatched by Unity. Issue is occurring with iOS build to physical device.

I've tried adding event listeners manually, but still a no-go.

The message is being dispatched by Unity with the following implementation:

public class MenuManager : MonoBehaviour
{
    public Button SignUpButton;
    public Button LoginButton;

    void Awake()
    {
        SignUpButton.onClick.AddListener(routeToSignUp);
        LoginButton.onClick.AddListener(routeToLogin);
    }
    void routeToSignUp() {
      Debug.Log("signup button clicked");
      UnityMessageManager.Instance.SendMessageToRN("SignUp");
    }

    void routeToLogin() {
      Debug.Log("login button clicked");
      UnityMessageManager.Instance.SendMessageToRN("Login");
    }
}
const UnityScreen = () => {
  const onMessage = (handler) => {
    console.log(handler);
  };

  return <UnityView style={s.unity} onMessage={onMessage} />;
};

However, after Metro is refreshed, I can still see the Debug.Log's output to Xcode which tells me that SendMessageToRN should be invoking but React Native is unable to receive the messages after a single refresh.

@dave-vazquez
Copy link
Author

For anyone running into the same issue, a work-around for this is not to refresh using Metro, but simply closing and re-opening the application on the device. It's the equivalent of refreshing the Metro server.

@shhhiiiii
Copy link

shhhiiiii commented Aug 23, 2021

Hi, Im experiencing nearly the same situation but for my side i dont want to close the app since its not necessary.

The scenario is :
First open of unity view is perfectly working.
then I used ** Application.Unload(); ** to unload unity and navigate to other react native screen,
When navigate again to unity view, Unity will reload just fine and will work properly,

But the problem is that messaging is distorted. Unity still can send message and will be receive in react native side, But for react native part when attempt to send message to unity view. Unity will not be able to receive the message.

Im suspecting that react native still trying to send message from the previous view that has been unload.

Does anyone know how to fix this problem?

HELP PLEASE!!

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

No branches or pull requests

2 participants