My game is using System.Net sockets. My TCPClient and Client Network Handle which listens for incoming data, are both scripts on a game object. They’re set to not destroy on load.
On the client, when the login button is clicked the player’s account details are checked by the server. The server then instructs the client to change to the gameplay scene, however changing scenes seems to lose the client socket connection.
I’ve also noticed while trying LoadSceneAsync, that coroutines also break.
Just wondering if anyone’s ever come across this and if they can suggest a way forward.
You’re probably running multiple threads for reading/writing to the socket. Make sure you’re not loading the scene from one of those threads, as the error is essentially telling you.
I recommend making it where once the TCP packet is finished and ready to be processed, add it to a list/handler (Make sure to use locks/some other method to make it thread safe) and have the main thread cycle through that list every frame and process the packets on the main thread.