Animation prevents script from working

Godot Version

v4.4.1.stable.mono.official [49a5bc7b6]

Question

I’m a beginner in Godot, and I’ve been trying to put together a point-and-click game with little animations. I wrote a script for picking up and placing objects (extends Sprite2D):

Summary

var dragging=false
var obj_offset=Vector2(0,0)

func _process(_delta):
if dragging:
position = get_global_mouse_position()-obj_offset
#without the -obj_offset the object will snap to the center of the mouse

#Leaf1
func _on_bl_1_button_down() → void:
dragging=true
obj_offset=get_global_mouse_position()-global_position
func _on_bl_1_button_up() → void:
dragging=false

#Leaf2
func _on_bl_2_button_down() → void:
dragging=true
obj_offset=get_global_mouse_position()-global_position
func _on_bl_2_button_up() → void:
dragging=false

#Leaf3
func _on_bl_3_button_down() → void:
dragging=true
obj_offset=get_global_mouse_position()-global_position
func _on_bl_3_button_up() → void:
dragging=false

#Leaf4
func _on_bl_4_button_down() → void:
dragging=true
obj_offset=get_global_mouse_position()-global_position
func _on_bl_4_button_up() → void:
dragging=false

And made a few looped animations that are meant to play in the scene:

Summary

extends AnimationPlayer

func _ready():
speed_scale = 0.412
play(“Leaf1Move”)
play(“Leaf2Move”)
play(“Leaf3Move”)
play(“Leaf4Move”)

The animations are preventing the script from working aka. picking up and putting down the objects. I attempted to pause()/stop(false) the animations in the AP’s script once the button (sprite) is clicked (via _on_button_pressed()) but neither works. Is there a way to make the button press/object pickup stop the animation? Or for the pickup script to work while the animation is playing?

Here’s a link to a video with my struggle → google drive LINK

I think this is because you are trying to manually change the position of the object using the mouse drag, while the AnimationPlayer animates the object’s position. This causes a conflict to which Godot will prioritize the animation rather than the input. Try stopping the animation while the object is being picked up, or only play the animation when the object is not being moved. Also, the button child of the Sprite2D might be unnecessary. Try a Sprite2D - AnimationPlayer setup where each Sprite2D has an AnimationPlayer child. Put all the animation logic and input handling in the Sprite2D.