Hey,
I just finished the 7th section of the “Unity 2D RPG: Complete Combat System” course and got some problems in the last lecture of the “Section Cleanup.”.
Before that, the instanciation of weapons worked well, as did switching them.
But in this lecture, we tried to handle the problem of the NullReferenceException when pressing 4 and 5, but instead of fixing it, it just made more problems for me.
First, now the instanciation of weapons doesn’t work at all, and when starting the game, I get this error:
NullReferenceException: Object reference not set to an instance of an object
ActiveInventory.ChangeActiveWeapon () (at Assets/Scripts/Inventory/ActiveInventory.cs:48)
ActiveInventory.ToggleActiveHighlight (System.Int32 indexNum) (at Assets/Scripts/Inventory/ActiveInventory.cs:39)
ActiveInventory.Start () (at Assets/Scripts/Inventory/ActiveInventory.cs:18)
And when trying to switch to another weapon (any one of them, also 1-3), I get the following errors:
NullReferenceException: Object reference not set to an instance of an object
ActiveInventory.ChangeActiveWeapon () (at Assets/Scripts/Inventory/ActiveInventory.cs:48)
ActiveInventory.ToggleActiveHighlight (System.Int32 indexNum) (at Assets/Scripts/Inventory/ActiveInventory.cs:39)
ActiveInventory.ToggleActiveSlot (System.Int32 numValue) (at Assets/Scripts/Inventory/ActiveInventory.cs:26)
ActiveInventory.<Start>b__3_0 (UnityEngine.InputSystem.InputAction+CallbackContext ctx) (at Assets/Scripts/Inventory/ActiveInventory.cs:16)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at ./Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
NullReferenceException while executing 'performed' callbacks of 'Inventory/Keyboard[/Keyboard/1,/Keyboard/2,/Keyboard/3,/Keyboard/4,/Keyboard/5]'
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
I tried to fix it, but nothing worked. Can someone help me, please?