Invalid access to property or key 'hand_equip' on a base object of type 'null instance'

Godot Version

4.3

Question

I’m a little at a loss here trying to get a held item to turn invisible once there are none left in the slot but no matter what I try it always returns null

extends Button

@onready var background_sprite: Sprite2D = $Background
@onready var item_stack_gui: ItemStackGUI = $CenterContainer/Panel
@onready var player = get_tree().root.find_child("Player")

func update_to_slot(slot: InventorySlot) -> void:
	if !slot.item:
		item_stack_gui.visible = false
		background_sprite.frame = 0
		player.hand_equip.visible = false
		return
		
	item_stack_gui.inventorySlot = slot
	item_stack_gui.update()
	item_stack_gui.visible = true
	
	background_sprite.frame = 1
extends Node2D

var hand_equip : Node2D

func _ready():
	if get_children().is_empty(): return
	
	hand_equip = get_children()[0]

func add_hand_equip(new_hand_equip) -> void:
	if hand_equip && hand_equip.name == new_hand_equip.name: return
	
	if hand_equip:
		remove_child(hand_equip)
		
	hand_equip = new_hand_equip
	add_child(new_hand_equip)

func remove_hand_equip() -> void:
	remove_child(hand_equip)
	hand_equip = null

Are you sure you’re not calling ‘remove_hand_equip’ at any point before you call ‘update_to_slot’?

And what is slot.item? Is hand_equip null when that is true?

I know you probably already checked this, but it’s worth double checking. And I really need more information, like where you’re calling all these methods and the script where slot.item is stored.