0

I am using Appwarp api for a multiplayer game. I am getting an error when i am calling Invoke("recoverConnection", 5).

public void onConnectDone(ConnectEvent eventObj)  
{  
    Log ("onConnectDone : " + eventObj.getResult ());  

    if (eventObj.getResult () == 0)   
    {
        recoveryErrorCode = 0;  
        WarpClient.GetInstance ().JoinRoomInRange (0, 5, true);  
    }   
    else if (eventObj.getResult () == 9)  
    {  
        this.Invoke("recoverConnection", 5);  
    }  
    else if (eventObj.getResult () == 8)   
    {  
        // reconnected  
    }  
}  

void recoverConnection()
{
    WarpClient.GetInstance ().RecoverConnection ();
}

The error is :

Invoke can only be called from the main thread.

Constructors and field initializers will be executed from the loading thread when loading a scene.

Peter B
  • 22,460
  • 5
  • 32
  • 69
Neel Gajjar
  • 11
  • 1
  • 2

1 Answers1

1

The callback onConnectDone is called on a separate thread so any UI related changes or Invoke functionality need to be called on main thread. You can use any plugin which can help you to call any method on main thread from any secondary thread. You can have a look at this link. This will help you to call Invoke method from main thread.

I hope this will help you.

Rajeev
  • 585
  • 3
  • 13
  • 2
    Please elaborate and add a few more details, so your answer will still be valid even when the link is broken. – CSharpie Oct 18 '16 at 05:43