I use this Tracking kills for Quests? all the time in my game. It worked great then recently I ran into the issue described in the bottom of the thread where it appeared that Check or Evaluate wasn’t being called. It seems the thread doesn’t fully reveal the root cause or the solution.
The reason some people have the problem and some people don’t may be due to how your predicates are set up.
If you have multiple literals in your predicate (screenshot below of what I mean) what may happen is that the Check method could return “false” before all literals in your predicate have been evaluated. If that happens… then Evaluate will not run for all literals in the predicate and if Evaluate does not run, then RegisterCounter will not run. If RegisterCounter doesn’t run, then counts won’t be summed up in your achievement counter.
There are two ways to fix this
- Explicitly call RegisterCounter as part of your quest granting / initialization
- In the inspector on your DeathCounter component make sure “Only If Initialized” is false
You don’t need to do both. The right choice will depend on how your scene or quest is set up. I actually make use of each approach in my game (not at the same time) because I have different situations where one is appropriate and the other isn’t.
public bool? Evaluate(EPredicate predicate, string[] parameters)
{
if (predicate == EPredicate.HasKilled)
{
if (int.TryParse(parameters[1], out int intParameter))
{
RegisterCounter(parameters[0]);
return counts[parameters[0]] >= intParameter;
}
return false;
}
return null;
}