this is an occasional bug that currently exists
If you kill an enemy, quit to the main menu and return, and then kill another enemy, or maybe even get close to any sort of pickup and hit the ‘P’ key (the one assigned to pickup items off the ground), you’ll get this error from time to time:
MissingReferenceException while executing 'performed' callbacks of 'Player/Pickup[/Keyboard/p]'
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)
MissingReferenceException while executing 'performed' callbacks of 'Player/Pickup[/Keyboard/p]'
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)
If I’m not mistaken, I think last time I dealt with something like this, when working on the Resource Gathering System, it was fixed by unsubscribing from an event of some sort, but… that’s not the case for me now, and here’s what I currently have in ‘PickupFinder.cs’:
using System.Linq;
using RPG.Core;
using UnityEngine;
namespace RPG.Inventories
{
public class PickupFinder : RangeFinder<PickupTarget>
{
public PickupTarget GetNearestPickup()
{
CurrentTarget = Targets.OrderBy(t => Vector3.Distance(transform.position, t.transform.position)).FirstOrDefault();
return CurrentTarget;
}
protected override void AddTarget(PickupTarget target)
{
base.AddTarget(target);
target.OnPickedUp += RemoveTarget;
Debug.Log($"Pickup Finder: Adding {target.name}");
}
protected override void RemoveTarget(PickupTarget target)
{
base.RemoveTarget(target);
target.OnPickedUp -= RemoveTarget;
Debug.Log($"Pickup Finder: Removing {target.name}");
}
}
}
Any idea where else do I need to change my code to fix this?