0

hey im making a multiplayer game in unity using tcp protocol im using a new thread with loop for checking if there is message to receive

Thread ctThread = new Thread(getMessage);
ctThread.Start();

private void getMessage()
{
    while (true)
    {
        int buffSize = 0;
        byte[] inStream = new byte[10025];
        buffSize = mySocket.ReceiveBufferSize;
        theStream.Read(inStream, 0, buffSize);
        try
        {
            string returndata = System.Text.Encoding.ASCII.GetString(inStream);
            checkMessage(returndata);
        }
        catch { }
    }
}

every thing is working fine but when i recive message from the server to change the active canvas or something like this:

cnv.SetActive(false);

i get this error:

SetActive can only be called from the main thread.

and not just with SetActive almost with everything i get the same error

0 Answers0