question

andymaddison avatar image
andymaddison asked

Cloud functions vs client side code for leaderboards

I have some PlayFab code in my Unity game to retrieve a leaderboard. I make 3 calls to PlayFab to construct my own leaderboard object. I decided it would be good idea to combine these 3 calls into a single cloud function (Azure) so I could just make one call to PlayFab. I have this working but I notice that the single cloud function call takes slightly longer than the 3 separate calls combined. Is this expected?

Which way do you prefer it to be done? Less calls is better?

I have a Leaderboard class I that need to use in both my Unity game code and in the Azure cloud function code. I reference the same source file in both projects and do this

#if NETCOREAPP3_1
using PlayFab.ServerModels;//Azure
#else
using PlayFab.ClientModels;//Unity
#endif

Do the representation of PlayFab classes in both ServerModels and ClientModels always match?

Do you foresee any problems with what I'm doing?

CloudScriptunity3dLeaderboards and Statistics
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

May I know how did you retrieve the leaderboard in Unity & Azure Function? Did you use async-await both in Unity & Azure Function? Would you please share some code on that(feel free to obfuscate sensitive info)?

There are some slight differences between the classes in ServerModels and ClientModels, take GetLeaderboardAroundPlayerResult in ClientModels for instance, however, the one defined in ServerModels is called GetLeaderboardAroundUserResult. And, “PlayFabId” and “MaxResultsCount” can be null in GetLeaderboardAroundPlayerRequest while in GetLeaderboardAroundUserRequest this is not allowed. Those differences are reasonable because Client-side and Server-side have different contexts.

4 comments
10 |1200

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

andymaddison avatar image andymaddison commented ·

In Unity I use coroutines to wait for the results, and in Azure I use await.

Basically in Unity I call

PlayFabClientAPI.GetLeaderboard

PlayFabClientAPI.GetPlayerStatisticVersions

PlayFabClientAPI.GetLeaderboardAroundPlayer

And in Azure I call

PlayFabServerAPI.GetLeaderboardAsync

PlayFabServerAPI.GetPlayerStatisticVersionsAsync

PlayFabServerAPI.GetLeaderboardAroundUserAsync

The PlayFab class I used across both projects in my shared class is PlayerLeaderboardEntry.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan andymaddison commented ·

So, the way you did in Unity (using coroutines), without having to wait for the previous request to complete first and then make the next one, is similar to using await in Azure, we can think of both of them as asynchronous.

After the ExecuteFunction call is made to PlayFab, PlayFab will subsequently make a call to Azure Function, waits for its response, and return the result back to the client side. However, making three async calls directly to PlayFab could be less time-consuming in such case. That explains why the single cloud function call takes slightly longer than the 3 separate calls combined.

0 Likes 0 ·
andymaddison avatar image andymaddison Citrus Yan commented ·

You are misunderstanding. In Unity I wait for each call in turn (because each subsequent call depends on the result of the previous). This is the same in Azure.

0 Likes 0 ·
Show more comments

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]