Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoke method in main thread from other thread
    primarykey
    data
    text
    <p>I get error like this in unity3d console:</p> <blockquote> <p>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.</p> </blockquote> <p>What I'm trying is execute method which seems to be defined in main thread like "Instantiate()"</p> <p>How can I invoke this method or call main thread to execute it?</p> <p><strong>EDIT</strong></p> <pre><code>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); ... </code></pre> <p>and the thread is:</p> <pre><code>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); } } </code></pre> <p>when i call processCommand i have there the method: Instantiate()</p> <p><strong>EDIT 2</strong></p> <p>I tried this also <a href="http://forums.asp.net/t/1777525.aspx/1" rel="nofollow">Link</a>, when i get the ManagedThreadId from currentThread i get 1 (which seems to be main thread) but i get again the same error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload