.visible issues with animatedsprite2d

Godot Version

4.1.1

Question

I have two scripts: PickaxeSwing and PickaxeAnimGetter

PickaxeSwing:

extends CollisionShape2D

var pickaxeanim
var pickaxecollision

func ready():
	pickaxecollision = $"."
	
	pickaxecollision.set_deferred("disabled", true)
	print("URRRHRG")

func _process(delta):
	pickaxecollision = $"."
	
	pickaxecollision.set_deferred("disabled", true)
	PickaxeAnimGetter.pickaxeanim_visible_off()

PickaxeAnimGetter:

extends AnimatedSprite2D

var pickaxeanim
# Called when the node enters the scene tree for the first time.
func _ready():
	pickaxeanim = $"." # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	pickaxeanim = $"."

func pickaxeanim_visible_off():
	pickaxeanim = $"."
	pickaxeanim.visible = false
	print("got it")

func pickaxeanim_visible_on():
	pickaxeanim.visible = true

The script is printing “got it” every tick, so it’s making it to the correct function, just not working. The pickaxe sprite is not turning invisible.

Have you made sure the shown sprite is not coming from another node? Your code looks alright (although it’s needlessly verbose and none of this needs to happen in _process), I’m fairly certain the issue is somewhere else. Have you checked the remote tree to make sure that the visible property actually gets changed to false?

How do I do that?

Run the game, leave it open in the background and change back to the editor window. In the scene tree dock, you should now see two new buttons: “Remote” and “Local”. “Local” is the regular scene tree that you set up in the editor. “Remote” is the scene tree as it looks right now, in the running game. That is, if you add or remove nodes at runtime or modify any properties, those changes should show up here. So click on “Remote” and then unfold the tree until you find your AnimatedSprite, select it and check the inspector to see if the visible property is set or not.