Epic Account Services and Achievements

Hey there,

I’ve been trying to get achievements working in my Unity game but I am having trouble understanding the process.

The achievements are all setup in dev, stage, and live. I have a script that connects to epic when you launch the game and then allows you to unlock the achievements.

However here are my issues:

  1. If I try to unlock and achievement using my dev account, I get “invaliduser”, even though the debug outputs my account ID correctly:
    public void UnlockEpicAchievement(string ID)
    {
        Debug.Log("unlocking " + ID + " for " + localUserID); **<-- this debug shows the right ID**
        UnlockAchievementsOptions unlockAchievementsOptions = new UnlockAchievementsOptions();
        unlockAchievementsOptions.UserId = ProductUserId.FromString(localUserID);
        unlockAchievementsOptions.AchievementIds = new Utf8String[] { ID };
        s_PlatformInterface.GetAchievementsInterface().UnlockAchievements(ref unlockAchievementsOptions, new object(), SetAchievementCallback);
    }

    private void SetAchievementCallback(ref OnUnlockAchievementsCompleteCallbackInfo data)
    {
        if (data.ResultCode == Result.Success)
            Debug.Log("Epic Achievement Unlocked");
        else
        {
            Debug.Log(data.ResultCode.ToString()); **<-- this outputs invaliduser**
        }
    }
  1. If I try to launch the game as a standard player, I get an Epic window that says I do not have access to this product - even though I have a live key and all the settings in my connection manager are pointing to the live sandbox, etc.

And this brings me to ask - Do I need to setup Epic Account Services and have the Brand Settings all setup in order for achievements to work?

Furthermore, is using the exchange code credential type the correct way to authenticate? Literally all I want to do is unlock achievements. No multiplayer, cross platform, leaderboards, or anything like that.

Any help is much appreciated.

1 Like

Do I need to setup Epic Account Services and have the Brand Settings all setup in order for achievements to work?

Yes, definitely.

**Debug.Log("unlocking " + ID + " for " + localUserID); ← this debug shows the right ID

This is the wrong ID, actually. I made the same mistake, and it took forever to figure out. You cannot pass in the user ID from auth, you have to pass in one that you get back from their connect interface.

In other words, you are trying to use a Epic.OnlineServices.EpicAccountId, but you have to be using a Epic.OnlineServices.ProductUserId.

In order to get that second kind of ID, you have to first log in and get the EpicAccountId (which it looks like you did correctly), then you have to use epicPlatformInterface.GetConnectInterface(); and do the following:

Epic.OnlineServices.Auth.CopyIdTokenOptions copyIdTokenOptions = new Epic.OnlineServices.Auth.CopyIdTokenOptions()
{
    AccountId = epicSelectedAccount//Epic.OnlineServices.EpicAccountId.FromString( epicSelectedAccount.ToString() )
};

Epic.OnlineServices.Result result = authInterface.CopyIdToken( ref copyIdTokenOptions, out Epic.OnlineServices.Auth.IdToken? userAuthToken );

That gives you an IDToken which will let you log in via the second part (this is the part that requires a Client, and an Application with that client, with the brand stuff). That looks like this:

Epic.OnlineServices.Connect.LoginOptions connectLoginOptions = new Epic.OnlineServices.Connect.LoginOptions()
{
    Credentials = new Epic.OnlineServices.Connect.Credentials()
    {
        Type = Epic.OnlineServices.ExternalCredentialType.EpicIdToken,
        Token = userAuthToken?.JsonWebToken
    }
};

epicConnectInterface.Login( ref connectLoginOptions, null, delegate ( ref Epic.OnlineServices.Connect.LoginCallbackInfo connectLoginCI_A )
{
    if ( connectLoginCI_A.ResultCode == Epic.OnlineServices.Result.Success )
    {
        epicProductUserID = connectLoginCI_A.LocalUserId;
        IsEpicLoggedIn = true;
        ArcenDebugging.LogSingleLine( "Epic: Connect login succeeded (user ID " + epicProductUserID.InnerHandle.ToInt64() + ").", Verbosity.DoNotShow );

    }
    else if ( Epic.OnlineServices.Common.IsOperationComplete( connectLoginCI_A.ResultCode ) )
    {
        if ( connectLoginCI_A.ResultCode == Epic.OnlineServices.Result.InvalidUser )
        {
            Epic.OnlineServices.Connect.CreateUserOptions createOptions = new Epic.OnlineServices.Connect.CreateUserOptions()
            {
                ContinuanceToken = connectLoginCI_A.ContinuanceToken
            };

            epicConnectInterface.CreateUser( ref createOptions, null, delegate ( ref Epic.OnlineServices.Connect.CreateUserCallbackInfo createLoginCI )
            {
                if ( createLoginCI.ResultCode == Epic.OnlineServices.Result.Success )
                {
                    epicProductUserID = createLoginCI.LocalUserId;
                    IsEpicLoggedIn = true;
                    ArcenDebugging.LogSingleLine( "Epic: Connect login successfully created new user connection: " + createLoginCI.LocalUserId.InnerHandle.ToInt64() + ").", Verbosity.DoNotShow );
                }
            } );
        }
        else
            ArcenDebugging.LogSingleLine( "Epic: Connect login failed: " + connectLoginCI_A.ResultCode, Verbosity.DoNotShow );
    }
} );

Note that this has some added gotchas in there. Specifically, you will NOT have a ProductUserID on first run. So you have to create one for the user, and then use it, in the manner noted above.

More info: Accessing EOS Game Services with the Connect Interface - Epic Online Services

And this shows the fix for the CreateUser being required: https://eoshelp.epicgames.com/s/question/0D54z00007U8AtNCAV/login-with-devauthtool-fails-on-tokengrant?language=en_US

Anyway, so the bottom line is that there are three levels of ID token you have to go through to log in.

Epic.OnlineServices.EpicAccountId becomes Epic.OnlineServices.Auth.IdToken becomes Epic.OnlineServices.ProductUserId.

In various interfaces like achievements, it is asking for a Epic.OnlineServices.ProductUserId explicitly, so until you go through this startup process, you can’t use achievements or similar.