Can't send data to Unity from React app with unityContext.send #242
-
First, I created a project and a scene in Unity 2020 Editor.
its my c# func. I think my problem in time when i try to send data. After all i check my unityContext.send for correctness ; I wait for my Debug.Log() in browser console like in function start:
this Debug.Log(gameObject.name); and Debug.Log("start App"); work correctly Can you help me, please |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Here os our React code, which is connected to Unity
|
Beta Was this translation helpful? Give feedback.
-
@jeffreylanters we need help in this issue |
Beta Was this translation helpful? Give feedback.
-
Hi. You should create your Unity Context model outside of your functional component, or place it within a mount cycle using UseEffect. Because in your example the Unity Context is recreated each render which results in the Unity Context losing its reference to the Unity Instance. See the documentation for further instructions and examples. |
Beta Was this translation helpful? Give feedback.
-
This is a significant problem. My React app always loses context in between if I receive a message from unity and then after an async delay tries to sendMessage back to Unity. |
Beta Was this translation helpful? Give feedback.
Hi. You should create your Unity Context model outside of your functional component, or place it within a mount cycle using UseEffect. Because in your example the Unity Context is recreated each render which results in the Unity Context losing its reference to the Unity Instance. See the documentation for further instructions and examples.