Change tool equipment in 2D game

@tool
extends Sprite2D

class_name HandEquip

@export var equipped_item : EquippableItem :
set(next_equipped):
print("Equipped ", next_equipped.display_name)
equipped_item = next_equipped
self.texture = equipped_item.texture

func _on_area_2d_body_entered(body):
if(equipped_item.has_method(“interact_with_body”)):
equipped_item.interact_with_body(body)


@tool
extends Button

class_name ItemButton

@export var item : Item :
set(item_to_slot) :
item = item_to_slot
icon = item.icon

var hand_equip : HandEquip = null

func _ready() :
if(not Engine.is_editor_hint()):
connect(“pressed”, _on_pressed)

func _on_pressed() :
if(not Engine.is_editor_hint()):
if(item is EquippableItem) :
print("Item : ", item.display_name)
print("hand_equip : ", hand_equip)
if(hand_equip != null) :
hand_equip.equipped_item = item


output
Godot Engine v4.2.stable.official.46dc27791 - https://godotengine.org
Vulkan API 1.3.260 - Forward Mobile - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1060 3GB

Equipped base_axe
Item : base pickaxe
hand_equip :

— Debugging process stopped —

i want to know how to fix it. I check remote when i play game. its show me null in equipped item i try to fix it but not a change.

Is null because you are setting it to null:

var hand_equip : HandEquip = null

You are not setting any value for hand_equip after that.

How do i set value for hand_equip to change it when i click.i try to write it but its not working

I don’t know LOL what should be hand_equip? From what I can understand, when you press a button, you equip a different item, possibly on a hand(??). Please provide more details.

Also, when posting your code, use the code formatting for a better read. For example:

@tool
extends Sprite2D

class_name HandEquip

@export var equipped_item : EquippableItem :
set(next_equipped):
print("Equipped ", next_equipped.display_name)
equipped_item = next_equipped
self.texture = equipped_item.texture

func _on_area_2d_body_entered(body):
   if(equipped_item.has_method(“interact_with_body”)):
      equipped_item.interact_with_body(body)

im sorry but like u said its change equip_hand when i pressed button
but its not changing cause its null

Do you mind posting a screenshot of your scene? Maybe it can make easier to understand your case. It’s still unclear to me what should be hand_equip and this is what you need to define. Is this a node? Is in the tree? Are you supposed to instantiate it? Should you get it from a NodePath? Where is this hand_equip object?

Oh i find a solution that today. I forgot to group so its cause my player was null and its broke from the beginning. I really thanks it for you help. right now i have problem which is i press button and my animation also working cause i code it when i left click its play animation