Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Internal_CloneSingle Error

Discussion in 'Editor & General Support' started by geyapingcn, Aug 2, 2011.

  1. geyapingcn

    geyapingcn

    Joined:
    Jul 29, 2010
    Posts:
    25
    In one cs file I defined a class named "ConnectServer" which connected to the server:
    Code (csharp):
    1.  
    2.     public event EventHandler Changed;
    3.     BeginRecieve(){
    4.         ...
    5.         AsyncCallback callback = new AsyncCallback(OnData);
    6.         connection = socket.BeginReceive(coords, 0, coords.Length, SocketFlags.None, callback, null);
    7.     }
    8.     private void OnData() {
    9.         GPSDATA gps = (GPSDATA)BytesToStuct(coords, typeof(GPSDATA));
    10.         gpslist.Add(gps);
    11.         if (Changed != null)
    12.             Changed(this, EventArgs.Empty);
    13.     }
    14.  
    In the other Script:
    Code (csharp):
    1.  
    2.     public Transform trans;
    3.     void Start(){
    4.         cs = new ConnectServer();
    5.         cs.BeginRecieve();
    6.         cs.Changed += OnAddData;
    7.     }
    8.     OnAddData(){
    9.         Instantiate(trans);
    10.     }
    11.  
    but It can not work and occured an error:

    UnityEngine.Object:Internal_CloneSingle(Object)
    UnityEngine.Object:Instantiate(Object) (at C:\BuildAgent\work\6bc5f79e0a4296d6\Runtime\ExportGenerated\Editor\BaseClass.cs:65)
    ConnectServerTest:OnAddData(Object, EventArgs) (at Assets\ConnectServerTest.cs:30)
    ConnectServer:OnData(IAsyncResult) (at Assets\ConnectServer.cs:183)
    System.Net.Sockets.SocketAsyncResult:Complete()
    System.Net.Sockets.Worker:Receive()

    I don't know why this happen while It can be Instantiate successfully when I don't use the network.
     
    Last edited: Aug 2, 2011
  2. geyapingcn

    geyapingcn

    Joined:
    Jul 29, 2010
    Posts:
    25
    anybody Can Help ?

    In Unity3d, It cannot Instantiate object in asynchronous model ?
    Could it only check the added info in Update and cannot use event to callback in asynchronous model ?

    while in asynchronous model , print is not as normal can be double clicked to locate the print sententce. like follow:
     
  3. ManjiDM

    ManjiDM

    Joined:
    Nov 5, 2015
    Posts:
    7
    I'm a tad late but I think the problem lies on the fact that, in Unity3D, you can only instantiate GameObjects from the main thread.