Here is my Progression.cs script. I’m also using Unity 2020.3.30f1 if that helps.
using UnityEngine;
using System.Collections.Generic;
using System;
namespace RPG.Stats
{
[CreateAssetMenu(fileName = "Progression", menuName = "Stats/New Progression", order = 0)]
public class Progression : ScriptableObject
{
[SerializeField] ProgressionCharacterClass[] characterClasses = null;
Dictionary<CharacterClass, Dictionary<Stat, float[]>> lookUpTable = null;
public float GetStat(Stat stat, CharacterClass characterClass, int level)
{
BuildLookUp();
float[] levels = lookUpTable[characterClass][stat];
if (levels.Length < level)
{
return 0;
}
return levels[level - 1];
}
public int GetLevels(Stat stat, CharacterClass characterClass)
{
// This is where the issue happens.
float[] levels = lookUpTable[characterClass][stat];
return levels.Length;
}
private void BuildLookUp()
{
if (lookUpTable != null) return;
Debug.Log("Building Lookup");
lookUpTable = new Dictionary<CharacterClass, Dictionary<Stat, float[]>>();
foreach (ProgressionCharacterClass progressionClass in characterClasses)
{
var statLookUpTable = new Dictionary<Stat, float[]>();
foreach (ProgressionStat progressionStat in progressionClass.stats)
{
statLookUpTable[progressionStat.stat] = progressionStat.levels;
}
lookUpTable[progressionClass.characterClass] = statLookUpTable;
}
}
[System.Serializable]
class ProgressionCharacterClass
{
public CharacterClass characterClass;
public ProgressionStat[] stats;
}
[System.Serializable]
class ProgressionStat
{
public Stat stat;
public float[] levels;
}
}
}