Hidden nodes still in process

Where this script is attached?
What you want to disable?

Remember hiding a physics based node don’t disable him, you need either disable his collision shape or disable the node

Script is in the root of the scene. I want to hide area2d node. I tried hiding it’s collision but that doesn’t work too.

It will:

$Lava/CollisionShape2D.disabled = true

You need to disabled the collision of area 2d

1 Like

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()

    # Difficulty setup
    if Global.difficulty == "easy":
        $checkpoint.show()
        $Lava.hide()
    elif Global.difficulty == "normal":
        $checkpoint.hide()
        $Lava.hide()
    elif Global.difficulty == "lava":
        $checkpoint.hide()
        $Lava.show()

func _process(delta):
    # Safeguard: Ensure visibility check at every frame 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 and disable all processing
    hide()
    set_process(false)
    set_physics_process(false)
    set_process_unhandled_input(false)
    set_process_input(false)

    # Disable collision shapes
    for child in get_children():
        if child is CollisionShape2D:
            child.disabled = true
        elif child is CollisionPolygon2D:
            child.disabled = true

func activate():
    # Show and enable all processing
    show()
    set_process(true)
    set_physics_process(true)
    set_process_unhandled_input(true)
    set_process_input(true)

    # Enable collision shapes
    for child in get_children():
        if child is CollisionShape2D:
            child.disabled = false
        elif child is CollisionPolygon2D:
            child.disabled = false

func _on_Button_pressed():
    queue_free()
    Global.from_splash_screen = false
    get_tree().change_scene("res://Menu.tscn")

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

I used this one from chat gpt
1 Like

Try to replace is_visible_in_tree with visible? I am not sure why it is not working. I need to check the project maybe

When you want to disable the Area2D, try: $Lava.set_deferred("monitoring", false) or $Lava.CollisionShape2D.set_deferred("disabled", true)

@KingGD Never disable a physics node inside the physics frame, always should be done using call/set_deferred, otherwise this can cause a crash inside the physics server

This is working for me and I will keep using this simple thing until I work on more complex projects which need more brainstorming. Thank you for this :innocent:

1 Like

It is not a simple things, it is common to disable a collision shape. Otherwise if your problem solved then you can end this topic.

But I will have to do this a lot more time because I have many layers scene and I have to hide a lot of things so this will be tedious. That’s why I was finding an alternative way

1 Like

Can you give me some feedback and suggestions on my menu screen. And yes it is directly running on my phone because I am making my game in my mobile because I don’t have any pc or laptop.

1 Like

It looks great! Nice job! But actually I not have any suggestion on it. Otherwise you can end this topic by pressing the green solution button, on the post that helped you, maybe my one.

Actually I don’t have anyone to give me feedback. That’s why I asked for and thank you for you help. Have a great day/evening/night/morning whatever time it is.

1 Like

You can share it on Reddit, it is a good place for it. But you need to do this in proper tag, promo - looking for feedback

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