Hi folks,
I've been following a tutorial on implementing PlayFab in Unity, and until now I really love it.
I'm having an issue for cloud functions
Console logs an error :
InvalidCastException: Specified cast is not valid. PlayFabController.OnCloudUpdateStats (PlayFab.ClientModels.ExecuteCloudScriptResult result) (at Assets/Scripts/PlayFabController.cs:175) PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:217) PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:245) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:249) PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:196) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
The error brings me to my OnCloudUpdateStats()
private static void OnCloudUpdatePlayerStats(ExecuteCloudScriptResult result) { // Cloud Script returns arbitrary results, so you have to evaluate them one step and one parameter at a time Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult)); JsonObject jsonResult = (JsonObject)result.FunctionResult; object messageValue; jsonResult.TryGetValue("messageValue", out messageValue); // note how "messageValue" directly corresponds to the JSON values set in Cloud Script Debug.Log((string)messageValue); }
From the Documentation : https://api.playfab.com/docs/tutorials/landing-automation/writing-custom-cloud-script
It seems that the Documentation uses the deprecated JsonWrapper and also doesn't seem to mention the need of:
using PlayFab.Json;
EDIT - SOLVE :
I had to replace that line :
Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));
with
Debug.Log(PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer));