Invoking error handler due to abort(-1) when sending a string from Unity to React #453
Answered
by
JThunchanit
JThunchanit
asked this question in
Help Wanted!
-
Hello everyone, help needed! I want to send a string from Unity to the react side, then get this error and the react side freeze. As the error maybe the issue is on the unity side, but I don't know what the issue is Here is the error shown:
Here is the code in the Unity side: class SomeClass: MonoBehaviour
{
[DllImport("__Internal")]
private static extern void SendPlayerlist(string playerList);
void Start(){
AddPlayers();
}
public void AddPlayers()
{
if (players == null)
{
players = new PlayerList();
players.playerName = new List<string>();
}
foreach(Player player in PhotonNetwork.CurrentRoom.Players.Values)
{
//Debug.Log("<color=yellow>Current player count: </color>" + player.NickName);
players.playerName.Add(player.NickName);
}
#if UNITY_WEBGL && !UNITY_EDITOR
Debug.Log("<color=yellow>SendJSON: </color>" + JsonUtility.ToJson(players));
SendPlayerlist( JsonUtility.ToJson(players));
#endif
}
} Here is the code in the react side: function SomeComponent {
const GetPlayerList = useCallback((playerlist) => {
console.log("GetJSON");
console.log(playerlist);
},[]);
useEffect(() => {
addEventListener("SendPlayerList", GetPlayerList);
return () => {
removeEventListener("SendPlayerList", GetPlayerList);
};
}, [addEventListener, removeEventListener, GetPlayerList]);
} And here is the jslib: mergeInto(LibraryManager.library, {
SendPlayerList: function (playerList) {
try {
window.dispatchReactUnityEvent("SendPlayerList", UTF8ToString(playerList));
}
catch (e) {
console.warn("Failed to dispatch event");
}
},
}); Could anyone point out what I have done wrong. |
Beta Was this translation helpful? Give feedback.
Answered by
JThunchanit
Sep 22, 2022
Replies: 1 comment
-
Ok just the typo mistake... |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jeffreylanters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok just the typo mistake...