PlayEveryWare / eos_plugin_for_unity

Repository for PlayEveryWare's EOS Plugin for Unity, bringing the functionality of Epic Online Services to the Unity Game Engine.
https://eospluginforunity.playeveryware.com
288 stars 56 forks source link

Achievement overlay does not show up in Epic build #610

Closed MrCharli3 closed 6 months ago

MrCharli3 commented 6 months ago

Describe the bug I have added feedback to confirm that my code is indeed being called:

eosAchievementManager = EOSManager.Instance.GetOrCreateManager<EOSAchievementManager>(); eosAchievementManager.UnlockAchievementManually(key);

As you can see I use the supplied EOSAchievementManager, I did remove all other sample scripts and scenes though as I do not need those.

They key is correct, and if I run the achievement sample scene, it connects properly to my project and lists my achievements.

Is there something else I could be missing? I am in a dev environment but according to Epic support it should still work.

I use the following script for login:

using Epic.OnlineServices;
using Epic.OnlineServices.Auth;
using Epic.OnlineServices.Stats;
using PlayEveryWare.EpicOnlineServices;
using PlayEveryWare.EpicOnlineServices.Samples;
using UnityEngine;

public class EOSLogin : MonoBehaviour
{
    protected EOSAchievementManager achievementManager;

    // Start is called before the first frame update
    void Start()
    {
        Login();
    }

    void Login()
    {
        EOSManager.Instance.StartPersistentLogin((Epic.OnlineServices.Auth.LoginCallbackInfo callbackInfo) =>
        {
            // In this state, it means one needs to login in again with the previous login type, or a new one, as the
            // tokens are invalid
            if (callbackInfo.ResultCode != Epic.OnlineServices.Result.Success)
            {
                Debug.Log("Failed to login with Persistent token [" + callbackInfo.ResultCode + "]");

                EOSManager.EOSSingleton.EpicLauncherArgs argsEpic = EOSManager.Instance.GetCommandLineArgsFromEpicLauncher();

                EOSManager.Instance.StartLoginWithLoginTypeAndToken(LoginCredentialType.AccountPortal,
                                                                        argsEpic.epicUsername,
                                                                        argsEpic.authPassword,
                                                                        CreateAndConnectWithContinuanceToken
                                                                        );
            }
            else
            {
                HandleOnAuthSucceded(callbackInfo);
            }
        });

    }

    void CreateAndConnectWithContinuanceToken(Epic.OnlineServices.Auth.LoginCallbackInfo callbackInfo)
    {
        if (callbackInfo.ResultCode != Epic.OnlineServices.Result.Success)
        {
            // ask user if they want to connect; sample assumes they do
            EOSManager.Instance.CreateConnectUserWithContinuanceToken(callbackInfo.ContinuanceToken, (Epic.OnlineServices.Connect.CreateUserCallbackInfo createUserCallbackInfo) =>
            {
                print("Creating new connect user");
                EOSManager.Instance.StartConnectLoginWithEpicAccount(callbackInfo.LocalUserId, (Epic.OnlineServices.Connect.LoginCallbackInfo retryConnectLoginCallbackInfo) =>
                {
                });
            });

        }
        else
        {
            HandleOnAuthSucceded(callbackInfo);
        }
    }

    void HandleOnAuthSucceded(Epic.OnlineServices.Auth.LoginCallbackInfo callbackInfo)
    {
        Debug.Log("EOS LOGGED with token [" + callbackInfo.ResultCode + "]");

        StartLoginWithLoginTypeAndTokenCallback(callbackInfo);

        //init achievements
        achievementManager = EOSManager.Instance.GetOrCreateManager<EOSAchievementManager>();
        achievementManager.GetAchievementDefinitionCount();
        achievementManager.EnumerateCachedAchievementDefinitions();
        var userId = EOSManager.Instance.GetProductUserId();
        if (userId.IsValid())
            achievementManager.EnumerateCachedPlayerAchievement(userId);

        achievementManager.AddNotifyAchievementDataUpdated(OnAchievementDataUpdated);

        IncrementLoginStat();
    }

    //-------------------------------------------------------------------------
    public void StartLoginWithLoginTypeAndTokenCallback(LoginCallbackInfo loginCallbackInfo)
    {
        if (loginCallbackInfo.ResultCode == Epic.OnlineServices.Result.AuthMFARequired)
        {
            // collect MFA
            // do something to give the MFA to the SDK
            print("MFA Authentication not supported in sample. [" + loginCallbackInfo.ResultCode + "]");
        }
        else if (loginCallbackInfo.ResultCode == Result.AuthPinGrantCode)
        {
            ///TODO(mendsley): Handle pin-grant in a more reasonable way
            Debug.LogError("------------PIN GRANT------------");
            Debug.LogError("External account is not connected to an Epic Account. Use link below");
            Debug.LogError($"URL: {loginCallbackInfo.PinGrantInfo?.VerificationURI}");
            Debug.LogError($"CODE: {loginCallbackInfo.PinGrantInfo?.UserCode}");
            Debug.LogError("---------------------------------");
        }
        else if (loginCallbackInfo.ResultCode == Epic.OnlineServices.Result.Success)
        {
            StartConnectLoginWithLoginCallbackInfo(loginCallbackInfo);
        }
        else if (loginCallbackInfo.ResultCode == Epic.OnlineServices.Result.InvalidUser)
        {

            print("Trying Auth link with external account: " + loginCallbackInfo.ContinuanceToken);
            EOSManager.Instance.AuthLinkExternalAccountWithContinuanceToken(loginCallbackInfo.ContinuanceToken,
                                                                            LinkAccountFlags.NoFlags,
                                                                            (Epic.OnlineServices.Auth.LinkAccountCallbackInfo linkAccountCallbackInfo) =>
                                                                            {
                                                                                StartConnectLoginWithLoginCallbackInfo(loginCallbackInfo);
                                                                            });
        }
        else
        {
            print("Error logging in. [" + loginCallbackInfo.ResultCode + "]");
        }

    }

    //-------------------------------------------------------------------------
    private void StartConnectLoginWithLoginCallbackInfo(LoginCallbackInfo loginCallbackInfo)
    {
        EOSManager.Instance.StartConnectLoginWithEpicAccount(loginCallbackInfo.LocalUserId, (Epic.OnlineServices.Connect.LoginCallbackInfo connectLoginCallbackInfo) =>
        {
            if (connectLoginCallbackInfo.ResultCode == Result.Success)
            {
                print("Connect Login Successful. [" + connectLoginCallbackInfo.ResultCode + "]");
                //ConfigureUIForLogout();
            }
            else if (connectLoginCallbackInfo.ResultCode == Result.InvalidUser)
            {
                // ask user if they want to connect; sample assumes they do
                EOSManager.Instance.CreateConnectUserWithContinuanceToken(connectLoginCallbackInfo.ContinuanceToken, (Epic.OnlineServices.Connect.CreateUserCallbackInfo createUserCallbackInfo) =>
                {
                    print("Creating new connect user");
                    EOSManager.Instance.StartConnectLoginWithEpicAccount(loginCallbackInfo.LocalUserId, (Epic.OnlineServices.Connect.LoginCallbackInfo retryConnectLoginCallbackInfo) =>
                    {
                    });
                });
            }
        });
    }

    public void IncrementLoginStat()
    {
        var statsInterface = EOSManager.Instance.GetEOSPlatformInterface().GetStatsInterface();
        var userId = EOSManager.Instance.GetProductUserId();
        IngestStatOptions ingestOptions = new IngestStatOptions()
        {
            LocalUserId = userId,
            TargetUserId = userId,
            Stats = new IngestData[] { new IngestData() { StatName = "login_count", IngestAmount = 1 } }
        };

        statsInterface.IngestStat(ref ingestOptions, null, (ref IngestStatCompleteCallbackInfo info) =>
        {
            Debug.LogFormat("Stat ingest result: {0}", info.ResultCode.ToString());
            achievementManager.RefreshData();
        });
    }

    private async void OnAchievementDataUpdated()
    {

    }

}
andrew-hirata-playeveryware commented 6 months ago

Hello @MrCharli3,

I need some additional information before I can make any guesses on what could be the issue:

MrCharli3 commented 6 months ago

hello @andrew-hirata-playeveryware

Thanks for helping!

MrCharli3 commented 6 months ago

Not sure why, but today it works.