- Home /
WebSocketSharp event not spawning sprite
I am making a multiplayer game with WebSocketSharp. And when another player joins the server I want to spawn a sprite that represents the other player. But the code that spawns the sprite stops right at the Instantiate function. In console i see the "1" and nothing after that .
private IEnumerator Connect()
{
socket = new WebSocket("ws://localhost:8080");
socket.Connect();
//WebSocket onMessage function
socket.OnMessage += (sender, e) =>
{
//If received data is type text...
if (e.IsText)
{
Debug.Log(e.Data);
JSONNode jsonObj = JSON.Parse(e.Data);
Debug.Log("OtherPlayer = " + jsonObj["newPlayer"]);
if (jsonObj["newPlayer"] != "null")
{
Debug.Log("1");
Instantiate(OtherChar, SpawnPos, new Quaternion(0, 0, 0, 0));
Debug.Log("2");
}
}
};
//If server connection closes (not client originated)
socket.OnClose += (sender, e) =>
{
Debug.Log(e.Code);
Debug.Log(e.Reason);
Debug.Log("Connection Closed!");
};
yield break;
}
Comment
Answer by xxmariofer · Feb 25 at 09:39 PM
the only way code doesnt executes is because Instantiate method crashes and returns an error, simply read the error
also, that quaternion doesnt exist, change to
Quaternion.identity
I'm not getting any errors, thats the weird thing. And thanks for the reply
can you change
Debug.Log("1");
to
Debug.LogError("1");
and see if its printed?
I changed it and printed the 1 as an error. But still nothing after that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613053503im_/https://answers.unity.com/themes/thub/images/avi.jpg)