Forum C# PlayerIO thread doesn't play nice with Unity

PlayerIO thread doesn't play nice with Unity

Postby dsaunder » December 11th, 2011, 9:14 am

Hi all,

I just ran into a nifty problem that took me shamefully long to debug (learning that I can attach the Mono debugger to Unity helped :D ). It has to do with certain PlayerIO related callbacks straight up not working with Unity. Basically, if you have any code that interacts with Unity in some callback functions (server connect success in my case), Unity throws an exception along the lines of "such and such property cannot be accessed outside the main thread."

My specific case is auto-loading some level on server connection, and accessing the 'gameObject' property of a script throws an exception.

Is there any reasonable way to get the PlayerIO threading to play nice with Unity other than setting some signaling objects up and iterating over all of them in some per-frame Update function?

Thanks!

-D

[EDIT]
Here are some functions and their results:

PlayerIO.QuickConnect.Connect Success: Runs on the main thread.
PlayerIO.QuickConnect.SimpleRecoverPassword Success: Runs on the main thread.
PlayerIOClient.PlayerIO.QuickConnect.SimpleRegister Success: Runs on the main thread.
Multiplayer.CreateJoinRoom success: spawn a new thread!!! (this doesn't work in Unity.)
dsaunder
 
Posts: 23
Joined: July 22nd, 2010, 7:28 am

Re: PlayerIO thread doesn't play nice with Unity

Postby dsaunder » December 14th, 2011, 7:22 am

OK, so my code looks a little something like this:
Code: Select all
void HandleServerConnectSuccess( Connection connection )
{
    m_ServerConnectionSuccess = true;
}

...
void Update()
{
...
if( m_ServerConnectionSuccess == true )
{
doSomething();
m_ServerConnectionSuccess = false;
}
}


Is this actually a bug?

-D
dsaunder
 
Posts: 23
Joined: July 22nd, 2010, 7:28 am


Return to C#