question

tomgeorgin avatar image
tomgeorgin asked

Unreal Engine 4 Plugin - Asynchronous calls

Hello,

I have been working with the Unreal Engine 4 Plugin for PlayFab and have noticed, after profiling the game, that the calls to `WritePlayerEvent` tend to generate a hitch.

They seem to be executed on the GameThread (main Thread for Unreal Engine), and are causing hitches.

I will be using

WriteEvents

instead of

WritePlayerEvent

to reduce the number of calls I make, but there will still be a problem of hitch during that single WriteEvents call.

My question is:
Is there an option I missed that enables the plugin to handle its HTTP requests asynchronously (and send the request on a separate thread), or do I have to manage my own Thread and call the functions such as WriteEvents on a separate thread to ensure it's not causing hitches on the main thread?

Thank you very much for your help!

Tom

unreal
10 |1200

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

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi @tomgeorgin,

>>or do I have to manage my own Thread and call the functions such as WriteEvents on a separate thread to ensure it's not causing hitches on the main thread?

As a matter of fact, requests to PlayFab Client APIs are asynchronous. And OnSuccess and OnError are the asynchronous callbacks that will be invoked after PlayFab Client APIs complete.

According to the unreal SDK source code, it uses FHttpModule for Http request, which is asynchronous, however, it seems to me that it won't create a new thread.

Referring to this doc, for now, the PlayFab Unreal C++ SDK maintains state with static variables which are non-atomic and are not guarded by synchronization techniques. Hence PlayFab recommends limiting PlayFab calls to within the main Unreal thread. However, as I see it, using a separate thread to call functions such as WriteEvents won’t change those static variables since you only write events to PlayFab. You can have a try and see what happens.

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.

tomgeorgin avatar image tomgeorgin commented ·

Hello Citrus, thank you for your answer.

To clarify, I meant multi-threaded, not asynchronous. Yes, PlayFab requests are all Asynchronous but they are on the main thread (called GameThread in Unreal), and the plugin doesn't seem to give the option to do its logic on another thread (Which was my question initially).

Regarding HTTP module in Unreal, the "ProcessRequest()" function is very CPU intensive and causes the Hitch in our game.

I think there is no way around managing our own thread and sending the PlayFab requests on that other thread to do all of this (including the HTTP request) on a separate thread.

I was just curious if there was an option already included in PlayFab Plugin to do that, after your answer + looking through their code, it does not appear so.

Thank you for your time, I'll mark you as answer.

Best regards,
Tom

0 Likes 0 ·

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.