Show() method won't show the node after hide() in screen_exited signal in VisibleNotifierScreen2D

Godot Version

v4.4.1

Question

So it just the basic use of VisibleNotifierScreen2D, I try to hide when its outside using hide() and show it back again using show(). But the show() method seems not working because when I entered again, it still not visible, even though the collision is active. What I done wrong with my code?

Code

func _on_visible_on_screen_notifier_2d_screen_entered() -> void:
	show()
	animated_sprite_2d.visible = true
	set_process(true)
	set_physics_process(true)
	collision_shape_2d.disabled = false
	
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	hide()
	animated_sprite_2d.visible = false
	set_process(false)
	set_physics_process(false)
	collision_shape_2d.disabled = true

What’s your scene tree look like?

StaticBody2D

  • AnimatedSprite2D
  • CollisionShape2D
  • VisibleNotifierScreen2D

As explained in the VisibleOnScreenNotifier2D description:

Note: VisibleOnScreenNotifier2D uses the render culling code to determine whether it’s visible on screen, so it won’t function unless CanvasItem.visible is set to true.

So if you hide the node it won’t work.

You shouldn’t need to hide the node when it’s outside the screen. It won’t be visible anyway and it will be culled (skipped when rendering it).

3 Likes

Alrighty, thanks for the answer @mrcdk

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.