- Home /
Question by
sandeepraj · Apr 17, 2020 at 04:58 PM ·
networkingmultiplayer-networkingnodejs
Need Help in Sending JSONOBJECT to Node Js
This code does not work
socket.Emit("move", new JSONObject(VectorToJson(position)));
It is sending the null object to the node server
can anyone help in sending JSONObject to the node server
Comment
Answer by CmdrZin · Oct 19, 2020 at 05:06 AM
Try breaking it up a bit.
public static void Move(Vector3 current, Vector3 destination)
{
JSONObject jsonObject = new JSONObject(JSONObject.Type.OBJECT);
jsonObject.AddField("c", Network.VectorToJson(current));
jsonObject.AddField("d", Network.VectorToJson(destination));
socket.Emit("move", jsonObject);
}
public static JSONObject VectorToJson(Vector3 vector)
{
JSONObject jsonObject = new JSONObject(JSONObject.Type.OBJECT);
jsonObject.AddField("x", vector.x);
jsonObject.AddField("y", vector.z);
return jsonObject;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612231718im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to choose Google Play Realtime Multiplayer Host? 0 Answers
Network command is running on client? 1 Answer
Photon Networking not synchronizing 0 Answers
RPC and Command Calls OR Network messages for syncing variables across Server and Client? 0 Answers
When to process input in networked multiplayer game? 0 Answers