question

contact@gentlymad.org avatar image
contact@gentlymad.org asked

Unity: Coroutine problem when using PlayFabHTTP in Editor. Fix included

When using PlayFabHTTP from an editor script (i.e. uploading TitleData through an editor window) the Coroutine MakeRequestViaUnity in PlayFabHTTP.cs always "pauses" at yield return www;
Once you start dragging the editor window around, it will "unpause" and the InvokeCallback will finally be fired.
This is a known problem when using Coroutines/WWW inside the editor.

In our case this was easy to fix, as we are using UniRx and can therefor use its main thread dispatcher, which will work just fine in the editor.
So instead of calling 
instance.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));
in PlayFabHTTP.cs we use
MainThreadDispatcher.StartCoroutine(instance.MakeRequestViaUnity(requestContainer));


UniRx can be downloaded here
https://github.com/neuecc/UniRx


If you don't want to use UniRx, here are two other solutions:

An out of the box solution (which will freeze the editor while the coroutine is running) is described here
https://chicounity3d.wordpress.com/2014/02/12/coroutines-in-the-editor/

Also, there is a plugin on the asset store which lets you use coroutines in the editor (not tested)
https://www.assetstore.unity3d.com/en/#!/content/27373


While this is not a major bug (dragging around a window is ok as a workaround) i hope this helps others with the same problem ;)

10 |1200

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

brendan avatar image
brendan answered

Thanks! We'll make sure the tools team is taking this into consideration.

10 |1200

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

contact@gentlymad.org avatar image
contact@gentlymad.org answered

Update: Another fix might be using WaitUntil(). I have not tried it yet, but it might work.

http://docs.unity3d.com/ScriptReference/WaitUntil.html

10 |1200

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

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.