- Home /
Question by
Bugsy6 · Apr 12, 2020 at 10:19 PM ·
gameobjectinstantiateasyncasynchronous
Instantiate fails with no errors
I am trying to instantiate a GameObject into a scene after I receive a response from my server.
Currently I send the request to the server, receive a response and then call the instantiating method.
Everything works right up until the Instantiate line, where I get no errors and nothing happens. Even the Debug line above works, so I know it is reaching the method.
Any ideas? Is it to do with the Async Callback I have when I receive the response from the server.
NetworkHandler.cs
public void ReceiveData(IAsyncResult result)
{
int receivedDataLength = socket.EndReceive(result);
string receivedString = Encoding.ASCII.GetString(receiveData, 0, receivedDataLength);
CheckInput(receivedString);
}
void CheckInput(string input)
{
Debug.Log("Received: " + input);
switch (input)
{
case "Fleet Created":
FleetHandler.instance.FleetCreated();
break;
default:
Debug.Log("Input not recognised");
break;
}
socket.BeginReceive(receiveData, 0, receiveData.Length, SocketFlags.None, new AsyncCallback(ReceiveData), null);
}
FleetHandler.cs
public void FleetCreated()
{
Debug.Log("Fleet created");
GameObject fleet = Instantiate(fleetItem, fleetDisplayList) as GameObject;
}
Comment