I was following brackeys rpg tutorial and in stats episode I had a problem about modifiers not adding.
PlayerStat :https://hatebin.com/mrvgaqlryp
CharacterStats :https://hatebin.com/ctdgzwqqqn
Stat :https://hatebin.com/vzwnqrwubm
EquipmentManager:https://hatebin.com/iyquciehbq
Debug.Log("Equipment Changed"); this line works but rest doesnt.(it's in playerstat)
I get this error when I change equipment
#Problem About Adding Modifiers
1 messages · Page 1 of 1 (latest)
I get this error when I change equipment Object reference not set to an instance of an object PlayerStat.OnEquipmentChanged (Equipment NewItem, Equipment OldItem) (at Assets/Scripts/PlayerStat.cs:26) EquipmentManager.Equip (Equipment newItem) (at Assets/EquipmentManager.cs:38) Equipment.Use () (at Assets/Equipment.cs:24)
Did you copy paste the two if statements? The second conditional checks if OldItem is null but then uses NewItem as the argument.
{
oldItem = new Equipment();
onEquipmentChanged?.Invoke(null, oldItem);
}```
problem is here I think but I just dont know what should I put in there
The error says where the error is. PlayerStat.OnEquipmentChanged on line 26.
It looks like you may have copied the top if statement to create the bottom one and forgot to swap the variable used in the argument.
Do you mean the ones in EquipmentManager or the ones in PlayerStat?
PlayerStat
The error always includes the call stack. The top of the stack of that error says
PlayerStat.OnEquipmentChanged (Equipment NewItem, Equipment OldItem) (at Assets/Scripts/PlayerStat.cs:26)```
It mentions the method as well as the file name and line number.
I didnt get that error before adding this
Yes, but that's not the error.
That code raises an event which is where the error happens. If that code didn't exist previously, you didn't get the error because the code was never called.
I changed NewItems to OldItem and trying
I didnt get errors but get this warning Equipment must be instantiated using the ScriptableObject.CreateInstance method instead of new Equipment. UnityEngine.ScriptableObject:.ctor () Item:.ctor () (at Assets/Item.cs:9) Equipment:.ctor ()
but thats about icons in inventory slots
but still no modifiers
That sounds like a different bug, then.
For that warning, you can't use new to make new instances of classes that inherit from ScriptableObject. You have to use ScriptableObject.CreateInstance.
I'd recommend looking into using the debugger to more quickly find and solve issues.