Hidden nodes still in process

Godot 3.5

Hi can anyone help me. It’s not that complex but I can’t
figure out how to do it.

I want that if I hide a node than i should’t interect or collide or process. I am currently using Godot 3.5 is there any possible way ?

I made a demo scene just to try this but it’s not working.

extends Node2D

func _ready():

Connect the visibility changed signal

connect(“visibility_changed”, self, “_on_visibility_changed”)

Initial activation/deactivation based on visibility

if not is_visible_in_tree():
deactivate()

func _process(delta):

Optionally, you can check visibility here if needed

if not is_visible_in_tree() and is_processing():
deactivate()

func _on_visibility_changed():

Called when visibility changes

if is_visible_in_tree():
activate()
else:
deactivate()

func deactivate():
hide()
set_process(false)
set_physics_process(false)
set_process_unhandled_input(false)
set_process_input(false)

func activate():
show()
set_process(true)
set_physics_process(true)
set_process_unhandled_input(true)
set_process_input(true)

func _on_Lava_body_entered(body):
get_tree().reload_current_scene()

func _on_hide_pressed():
$Lava.hide()

func _on_show_pressed():
$Lava.show()


https://www.mediafire.com/file/njq0jy1e3zdd6ex/About+nodes+hiding.zip/file

My Godot project link

You can mention any user by “@” symbol. Anyway, it would easy to me if you write this codes in proper format.

``` Your Codes ```

func _ready():
	# Connect the visibility changed signal
	connect("visibility_changed", self, "_on_visibility_changed")
	# Initial activation/deactivation based on visibility
	if not is_visible_in_tree():
		deactivate()

func _process(delta):
	# Optionally, you can check visibility here if needed
	if not is_visible_in_tree() and is_processing():
		deactivate()

func _on_visibility_changed():
	# Called when visibility changes
	if is_visible_in_tree():
		activate()
	else:
		deactivate()

func deactivate():
	hide()
	set_process(false)
	set_physics_process(false)
	set_process_unhandled_input(false)
	set_process_input(false)
	
func activate():
	show()
	set_process(true)
	set_physics_process(true)
	set_process_unhandled_input(true)
	set_process_input(true)

func _on_Lava_body_entered(body):
	get_tree().reload_current_scene()


func _on_hide_pressed():
	$Lava.hide()


func _on_show_pressed():
	$Lava.show()
1 Like

I never used this function is_visible_in_tree() but you can try to use visible parameter for it.
Try to replace is_visible_in_tree() with visible

Okk let me try it

1 Like

Actually I found this code on reddit than I asked chat gpt to adjust accordingly for my script. But it didn’t work

1 Like

Chatgpt? Why? Just press CTRL + R and replace it in the code editor.

I changed all is_visible_in_tree(): to visible():

Actually it does not contains any bracket, it is only “visible”.

Ohh okk wait let me do that than

1 Like

What you want to say?

res://jjjj.gd:5 - Parse Error: The identifier “visible” isn’t declared in the current scope.

Please can you show a screenshot?

Here it is

1 Like

Which node did it extends?

Lol I totally ignored that :sweat_smile: my mistake

But if I hide the node it still can interact

Define a variable “can_interact”, make it false on deactivate, add a statement that if !can_interact: return in the interact function

Take a look I want that if node is hidden than it should behave like it doesn’t exist.

1 Like