Can be called from main thread Error in working with events for server Listeners in unity

i use QuObject source for connecting to socket io server for sending and getting Listenrs (emits). like this :

socketConnection = IO.Socket("127.0.0.1:3000");
socketConnection.On(QSocket.EVENT_CONNECT, () =>
{
  onConnectedSocket();
}             

and this is my codes for creating delegate and event :

public delegate void SocketConnectionListener(); 

public event SocketConnectionListener OnSocketConnectionListener;
protected virtual void onConnectedSocket() => OnSocketConnectionListener?.Invoke();

and when i want to use this event for handling the connection through another script i get error in this like

ConnectedMsg.SetActive(true);

the error is this :

SetActive() can only be called from the main thread.

so how can i solve this problem ?



Read more here: https://stackoverflow.com/questions/64419114/can-be-called-from-main-thread-error-in-working-with-events-for-server-listeners

Content Attribution

This content was originally published by unattainable at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: