Method does not see the object (NullReferenceException)

I am following some video tutorial, on yt, checked it 3 times and i couldn’t find mistake in my code but anytime i try to press on “item” i get

NullReferenceException: Object reference not set to an instance of an object
ItemSlot.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/Scripts/ItemSlot.cs:39)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()

and here is also the code:

[CreateAssetMenu]
public class Item : ScriptableObject
{
    public string itemName;
    public Sprite icon;
}
public class ItemSlot : MonoBehaviour, IPointerClickHandler
{
    [SerializeField] public Image image;

    public event Action<Item> OnRightClickEvent;

    private Item _item;
    public Item Item
    {
        get {return _item;}
        set
        {
            _item = value;

            if(_item == null)
            {
                image.enabled = false;
            }
            else
            {
                image.sprite = _item.icon;
                image.enabled = true;
            }
        }
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData != null && eventData.button == PointerEventData.InputButton.Right)
        {
            Debug.Log(Item.name);
            if (Item != null && OnRightClickEvent != null)
                OnRightClickEvent(Item);
        }
    }

    protected virtual void OnValidate()
    {
        if(image == null)
        {
            image = GetComponent<Image>();
        }
    }
}

I added whole code in the attachments

5086946–501002–code.txt (4.84 KB)

You null reference is on line 39. As you’ve excluded the using lines, I would guess that yourOnRightClickEvent action is null.

But why this is null? This accepts “Item” and get’s “Item”, to get to that point it has to exist

Maybe it’s the item. Which is line 39?

    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData != null && eventData.button == PointerEventData.InputButton.Right)
        {
            Debug.Log(Item.name);
            if (Item != null && OnRightClickEvent != null)
                OnRightClickEvent(Item); //that's 39
        }
    }