question

Dale Strickler avatar image
Dale Strickler asked

Can the Unity Client API run in a separate thread?

Unity is a multi-threaded system. But the main UnityEngine APIs are not thread-safe so they can only be called from the main Unity thread.

I plan on examining the PlayFab source code but I also wanted to get input from others in case I miss something.

Do any of the PlayFab calls make calls to the UnityEngine? If so likely they cannot run on a thread other then the main thread.

The way I designed PlayFab data sync calls PlayFab C# will push it off to another thread. (A side effect I did not plan on.) I am trying to decide if I should redesign before I code or if I should push ahead. Thread collisions are really hard to test for so it might test ok but still be hosed from time to time not hosed in the editor but hosed on a mobile device :-)

apisunity3d
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dale Strickler avatar image Dale Strickler commented ·

From reading the code I am guessing no! The Unity PlayFab SDK needs to be called from the main Unity thread. Confirmation from a developer who knows for sure would be great!

0 Likes 0 ·

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Theoretically, you can try using C# SDK in your Unity project instead, as that doesn’t make calls to the UnityEngine. In that case you can create a new thread and run PlayFab APIs in it without having to interfere with the main method too much. However, please note that the C# SDK is not designed for Unity projects hence we haven’t done much test on its performance in Unity, you can still give a try though.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dale Strickler avatar image Dale Strickler commented ·

Ah, interesting thought. Perhaps I should consider the C# SDK... more to think about. I keep ending up in callback hell and keep looking for a nice design pattern out of it. Using the Job System that Unity now has in preview can get ride of the callback hell but the Job don't run on the main thread so call the PlayFab Unity SDK will not work in the job system.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.