-
-
Notifications
You must be signed in to change notification settings - Fork 162
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 Send Message while Unity is not Instantiated. #474
Comments
I got the same issue migrating from version 8 to 9. It looks like the problem is that while you register a listener, that listener triggers SendMessage while the Unity component is still loading, I made it work by triggering SendMessage inside a useEffect that depends on an isLoaded state that becomes true once the component has been loaded, I already had that implementation with my own hook, however, I can see that UnityContextHook has the isLoaded property, that one should work |
@stevenzipgen can you send me the reference and code hint on how to use UnityContextHook. |
//this will throw: Unable to Send Message while Unity is not Instantiated ` const unityContext = useUnityContext(
//Storing a state to know when the app was loaded `const [rendererLoaded, setRendererLoaded] = useState(false);
|
This may help some other people: We had this error prop up when we disabled the splash screen and Unity logo. We re-enabled splash screen (disabled Unity logo though), and bam --- sendMessage works again. We're on 2022.2.1f1. Hope this helps. |
Hi there, getting this issue too - but mine is when I try to sendMessage() or addEventListener() in a component different to the main app.tsx, where my Unity build is being rendered. Any clue as to what I'm doing wrong? |
I have the same problem. "Unable to Send Message while Unity is not Instantiated." Unity 2021.3.23 What is the correct method to call sendMessage? Is it a library error or how are we calling it? It seems that unityInstance is always null. |
Same issue, code looks like:
And then elsewhere:
Whenever I try to send a packet over to Unity I will get the warning, however the test call I make in the |
Same problem using sendMessage from the hook. react-unity-webgl: 9.4.2 const {unityProvider, isLoaded, loadingProgression, |
I got the same issue, and I fixed the issue with this code const { unityProvider, sendMessage, isLoaded } = useUnityContext({
// ...
});
const socketIoClientRef = useRef<null | Socket>(null);
useEffect(() => {
if (!isLoaded) {
return;
}
socketIoClientRef.current = io('/');
socketIoClientRef.current.on(
'some-event',
({ messageId, value }) => {
if (messageId === 'some-message') {
sendMessage('something','something',value);
}
},
);
return () => {
socketIoClientRef.current?.disconnect();
};
}, [isLoaded]); |
isLoaded has to be added to the dependency of useEffect. And boom it will work |
i have the same issue but it works with this code
|
i have the same issue after follow the tutorial.
so i think everything is fine, just need to double check your code called on proper state. |
Please avoid duplicates
Language and Compiler
Vanilla JavaScript
What environment are you using?
Local Development Server
When does your problem occur?
When the Unity App is running
What does your problem relate to?
The problem seems React related
React-Unity-WebGL Version
9.3.0
React Version
17.0.39
Unity Version
2021.5f1
What happened?
Hello team, I am sorry to say that I am facing runtime issues within react, I have been trying to solve it for some days but without success.
WebGL Warning Log : When Call Unity Function Using Bridge :
**use-unity-context.js:121 Unable to Send Message while Unity is not Instantiated.
(anonymous) @
use-unity-context.js:121**
https://drive.google.com/file/d/1tttT2moMFzI8SN7M1LmG8zv4RNq7oI89/view?usp=share_link
3.And this function is called from the listener. And within it Unity communicates with SendMessage
https://drive.google.com/file/d/1xc00kEi81-y-yA3bX0wnyWNL230fZYvg/view?usp=sharing
But I get This Message in WebGL Log Console and not Send Message Unity Function: (All The Parameters are Verified)
https://drive.google.com/file/d/1pNFwVxxZq9_ELmniYFHDWUc91YuUUTWE/view?usp=sharing
And now , if I call this function from react button then it works fine. But if I call from unity listener, it doesn't give me function call inside unity.
I don't know if this is an issue or my coding.
Help me Please !
Reproducible test case
No response
Would you be interested in contributing a fix?
The text was updated successfully, but these errors were encountered: