#Problem About Adding Modifiers

1 messages · Page 1 of 1 (latest)

swift coral
#

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)

woeful mulch
#

Did you copy paste the two if statements? The second conditional checks if OldItem is null but then uses NewItem as the argument.

swift coral
woeful mulch
#

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.

swift coral
#

Do you mean the ones in EquipmentManager or the ones in PlayerStat?

woeful mulch
#

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.
swift coral
woeful mulch
#

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.

swift coral
#

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

woeful mulch
#

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.