Living Nightmare

I just spent the last 30 minutes debugging my code to see why my health/mana was not updating after implementing the additive/percentage modifiers. Printing debug.log everywhere… Then I started noticing that when I was printing my trait bonuses I was getting it printing twice for each one… Sure enough I somehow had two TraitStores on the Player. That breaks it big time.

I know when it happened too. I came to add the bonus trait values and did not see the TraitStore ANYWHERE so I added it figuring something didn’t save. Turns out it was there. I need sleep now.

But now that I have it working I don’t think it is working right. I set percentage modifier for Intelligence to be 2% for Mana…

Mana starts at 200… 2% should be 4 mana. 204… but I end up with 210. And each level just gives 10 mana. So it isn’t even cumulatively calculating it anyway. Which, fine(later I am realizing it is because of the progression SO. It actually RECALCULATES it all based off your new level and that base stat level. Definitely need to tweak that)… But I can’t get my head around why it is giving me 10 mana.

EDIT: Deleting the TraitStore and adding it back with the exact same values appears to have fixed that. My save file didn’t like it for current stats, but it appears to work now.

You can fix the issue of having multiple TraitStores (or any component, for that matter) by using an Attribute on the class:


namespace RPG.Stats
{
    [DisallowMultipleComponent] //Prevents multiple components on your GameObject
    public class TraitStore : MonoBehaviour, IModifierProvider, ISaveable, IPredicateEvaluator
    {
1 Like

Privacy & Terms