Hello, I’ve looked for similar questions but they all involve a game object or a monobehaviour but mine is a bit different (probably doing it the wrong way). I’m quite new to c# and Unity so apologies if this is obvious.
I have a GameManager
Class that contains an array of Character
classes, which in turn have CharacterStats
class that then have a CharacterStat
class. Based on that it’s only 4 classes deep so I think I’m hitting the Unity Serialisation Depth warning because of recursion(?).
The looping/recursion (as I’ve read) is because I’m passing in the CharacterStats class to the Stat class because I need a reference to it. I see people getting around this by accessing the instance or the game object then finding it with GetComponent but this won’t work in my case.
Is there a better way of accessing that “parent” class without passing it in as a parameter to the CharacterStat constructor?
Here is the code in question, you can see me passing in this
to the CharacterStat:
[System.Serializable]
public class CharacterStats {
public CharacterStat STA, STR, AGI;
public CharacterSkill Pistol, Bow;
public CharacterAttribute HP, NP, Speed;
public CharacterStats(Profession profession) {
STA = new CharacterStat(this, "Stamina", StatType.STA, profession.STA);
STR = new CharacterStat(this, "Strength", StatType.STR, profession.STR);
AGI = new CharacterStat(this, "Agility", StatType.AGI, profession.AGI);
Pistol = new CharacterSkill(this,"Pistol", StatType.Pistol, profession.Pistol, profession.PistolAffinitities);
Bow = new CharacterSkill(this,"Bow", StatType.Bow, profession.Bow, profession.BowAffinitities);
}
}