I get error like this in unity3d console:
INTERNAL_CALL_Internal_InstantiateSingle can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
What I'm trying is execute method which seems to be defined in main thread like "Instantiate()"
How can I invoke this method or call main thread to execute it?
EDIT
protected static void processCommand(String data) {
...
} else if(data.StartsWith("LOGGEDIN")) {
...
Vector3 pos = new Vector3(0, 1.2F, 0);
Quaternion rot = Quaternion.identity;
myModel = (GameObject)Instantiate(player, pos, rot);
...
and the thread is:
Thread tidListen = new Thread(new ThreadStart(ListenThread));
tidListen.Start();
private static void ListenThread() {
while(connected) {
int lData = myStream.Read(myBuffer, 0, client.ReceiveBufferSize);
String myString = Encoding.ASCII.GetString(myBuffer);
myString = myString.Substring(0, lData);
processCommand(myString);
}
}
when i call processCommand i have there the method: Instantiate()
EDIT 2
I tried this also Link, when i get the ManagedThreadId from currentThread i get 1 (which seems to be main thread) but i get again the same error.