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
290 stars 55 forks source link

Manual Achievements not working for me - First time using Epic games plugin for Unity #517

Closed BakiStudio closed 9 months ago

BakiStudio commented 9 months ago

Hello! Is there anybody who could help me with setting manually achievements for e.g Level 1 completed and it will trigger the achievement? I am kinda lost with this plugin, I tried to follow some old issues here but they didnt worked.

obrázok

I have something similiar with Steam API but Steam was way more easier than this. I want to reach something like this: obrázok

Thanks for any tips or advices.

paulhazen commented 9 months ago

Hi @BakiStudio, I assume that you've taken a look at the Achievements Demo?

Your first screenshot has me a little confused. The correct syntax in C# would be the following:


// the value of this would have to be the "achievementId," whatever value that 
// might be (from the Epic Online Services Developer Portal).
string level1_completed;

var achievementManager = EOSManager.Instance.GetOrCreateManager<EOSAchievementManager>();

achievementManager.UnlockAchievementManually(level1_completed);

The achievement manager can be found here: Assets/Scripts/EOSAchievementManager.cs.

Let me know if any of the above sheds further light on the situation or not :)

BakiStudio commented 9 months ago

Hello @paulhazen , Yes I looked but got confused really fast so I research some issues here on github and tried to make something. Thanks for the correct syntax. This is my current changed script: obrázok

However in the Unity console I am getting this error after clicking the button which should unlock achievement - NullReferenceException: Object reference not set to an instance of an object MenuController.UnlockAchievement () (at Assets/Scripts/MenuController.cs:48). I am kinda curious why because it looks like everything is set correctly by documentation. I have Singletons prefab in scene with EOS Host Manager and EOS Manager which initialize result is success and IDs of achievement are correct. I am used to Steam API when I tried this it made a fake Steam UI achievement pop-up at the bottom right corner (activated from Unity engine with zero uploaded builds). I am sorry if I am missing something I am just a 19yo student trying to expand my game on another stores. Thanks for any other tips and advices :)

paulhazen commented 9 months ago

@BakiStudio, it looks like you're doing everything correctly. However, the file Assets/Scripts/MenuController.cs is not a file that is in our repository, meaning it's a file you must have made, which makes it difficult for me to assist you in diagnosing. It's challenging to know whether the NullReferenceException you are experiencing is coming from the EOS Plugin (which is possible) or if it's coming from something wrong in your code.

Can you share your MenuController.cs code (or at least the parts of the file that are relevant to the NullReferenceException being thrown?

Everybody starts somewhere, this is how you learn! :)

BakiStudio commented 9 months ago

Hello @paulhazen, Yes I understand. The whole MenuController script is just public voids methods for buttons nothing connected with EOSAchievement etc. These are the main lines with connection to EOS plugin.

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro;
using PlayEveryWare.EpicOnlineServices.Samples;
using PlayEveryWare.EpicOnlineServices;

//EpicGamesStore
private EOSAchievementManager achievementManager;
public string level1_completed;

private void Awake()
{
    var achievementManager = EOSManager.Instance.GetOrCreateManager<EOSAchievementManager>();
}
public void UnlockAchievement()
{
    // This line is throwing a NullReferenceException
    achievementManager.UnlockAchievementManually(level1_completed);   
}

obrázok obrázok

In hierarchy there is a EOSManager prefab with EOSManager script with Initialize On Awake ticked on. I also tried different script which should trigger achievement for activating the checkpoint and it is showing same error in console.

obrázok The achievements on Developer Portal are still in Dev Stage, also there is no build on DevPortal yet, I am testing it in Unity engine for now with plugin integration.

Thanks for any help and advices! Have a nice day.

paulhazen commented 9 months ago

Try adding the following line inside your UnlockAchievement method right before your line of code that unlocks it:

achievementManager = EOSManager.Instance.GetOrCreateManager<EOSAchievementManager>();

Also, from what I can see your variable level1_completed has no value. So you may want to add to the end of it's declaration so that the line reads:

public string level1_completed = "level1_completed";