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

Unable to find Event Listener in Event System for Event #483

Open
2 tasks done
rounin-rp opened this issue Jan 24, 2023 · 1 comment
Open
2 tasks done

Unable to find Event Listener in Event System for Event #483

rounin-rp opened this issue Jan 24, 2023 · 1 comment
Assignees
Labels

Comments

@rounin-rp
Copy link

Please avoid duplicates

Language and Compiler

Babel and WebPack JavaScript

What environment are you using?

Local Development Server

When does your problem occur?

While the Unity App is loading

What does your problem relate to?

I don't know

React-Unity-WebGL Version

9.3.0

React Version

18.2.0

Unity Version

2021.3.14f1

What happened?

My unity app throws an event GetUserData as soon the scene gets loaded but I am getting the following warning/error in my browser console:
Unable to find Event Listener in Event System for Event {eventName: 'GetUserData'}

The most interesting this is that the issue is not occurring all the time, some times its working and some times not.

Reproducible test case

No response

Would you be interested in contributing a fix?

  • yes, I would like to contribute a fix
@flatypus
Copy link

flatypus commented Aug 31, 2023

I encountered the same problem running the example code on the docs. To fix it, we changed the code to

mergeInto(LibraryManager.library, {
  GameOver: function (userName, score) {
    const data = { userName: UTF8ToString(userName), score };
    const event = new CustomEvent("componentEvent", { detail: data });
    window.dispatchEvent(event);
  },
});

And on the react side:

const handleComponentEvent = ({ detail }: CustomEvent<{ userName: string, score: number }>) => {
  const { userName, score } = detail;
  console.log(userName, score)
};

useEffect(() => {
  window.addEventListener("componentEvent", handleComponentEvent as EventListener);
  return () => {
    window.removeEventListener("componentEvent", handleComponentEvent as EventListener);
  };
}, []);

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

No branches or pull requests

3 participants