question

sanjusah627 avatar image
sanjusah627 asked

,Code working on unity editor but not on build....

,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using TMPro;


public class PlayfabManager : MonoBehaviour
{
    public TMP_Text loginTXT;


    [Header("Values")]
    public string ammoAmount;
    public string medkitAmount;
    public string srvAmount;


    [Header("TXT")]
    public TMP_Text ammoTXT;
    public TMP_Text medkitTXT;
    public TMP_Text srvTXT;


    Menu menu;


    // Start is called before the first frame update
    void Start()
    {
        Login();
        
        menu = GetComponent<Menu>();
    }




    private void Update()
    {
        
    }


    void Login()
    {
        var request = new LoginWithCustomIDRequest
        {
            CustomId = SystemInfo.deviceUniqueIdentifier,
            CreateAccount = true
        };
        PlayFabClientAPI.LoginWithCustomID(request, OnSuccess, OnError);
    }


    public void GetData()
    {
        PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnDataRecieved, OnError);
    }


    void OnDataRecieved(GetUserDataResult result)
    {
        Debug.Log("Recieved");
        
        if (result.Data != null)
        {
            loginTXT.text = "Recieved";


            ammoTXT.text = "Ammo : " + result.Data["Ammo"].Value;
            medkitTXT.text = "Medkit : " + result.Data["Medkit"].Value;
            srvTXT.text = "SRV : " + result.Data["Survival"].Value;


            
        }
        else
        {
            loginTXT.text = "Recieved but not loaded";
        }
    }


    public void SaveData()
    {
        var request = new UpdateUserDataRequest
        {
            Data = new Dictionary<string, string>
            {
                {"Ammo", menu.ammoAmount.ToString()},
                {"Medkit", menu.medkitAmount.ToString()},
                {"Survival", menu.srvAmount.ToString()}
            }
        };
        PlayFabClientAPI.UpdateUserData(request, OnDataSend, OnError);
    }


    void OnDataSend(UpdateUserDataResult result)
    {
        Debug.Log("User Data Send");
        
    }


    void OnSuccess(LoginResult result)
    {
        Debug.Log("Successfully loggin Account Created");
        GetData();
        loginTXT.text = "Logged In";
    }


    void OnError(PlayFabError error)
    {
        Debug.Log("Error while login");
        loginTXT.text = "Error";
    }
}


hello, I am using unity game engine and the code is working on unity editor but when I build it, it not able to load anything from server.... please help me... I am using this code this is fully working on the editor but not when I build it for android do I need to do some specific setting for build.... please help...
unity3d
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

·
Gosen Gao avatar image
Gosen Gao answered

Do you mean API GetUserData is not loading data from PlayFab in an Android build? Since when you login with an Android device at the first time, it will create a new player, please check your Game Manager first to see if this player’s title data has been updated successfully. If this player’s title data is updated correctly, but you still cannot get it in Android build. Please change your OnError callback to debug more error message. Code below is for your reference.

loginTXT.text = "Error" + error.GenerateErrorReport();

Also for Android build, you may need to check app capabilities and enable network access permission for the client.

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.