How can i use VisibleOnScreenNotifier2D?

I created a Flappy Bird clone in Godot 4 using a tutorial on YouTube. However, today I encountered a problem with optimizing the game. On mobile devices, it runs with a significant delay because when the pipes go out of view, they don’t disappear and continue to exist, putting a load on the device. I know I need to use the VisibleOnScreenNotifier2D node, but I can’t just add this node and the check in the script for the pipes because it instantly triggers an error: “Invalid access to property or key ‘position’ on a base object of type ‘previously freed’.” and the game crashes. How can I fix this and improve the optimization of my game? Please help me in this difficult situation! Thank you very much in advance!
link tutorial - https://youtu.be/9f9t9eiCDAA?si=uaQiAjyB9K3evdhD

I think the pipes should handle movement on their own, they do not need to be in a outside pipes array.

Adding this _process to the pipe script means you shouldn’t have to keep a pipes array.

func _process(delta: float) -> void:
    position.x -= 120 * delta

Tutorial also doesn’t use delta so your game would be frame dependent.

1 Like

your way sounds plausible, but I can’t figure out how to write it in code. Can you please provide a pseudocode or demonstrate a solution?

I don’t have your code and my suggestion is to largely remove code, so I cannot make such changes without you first pasting what code you have, specificlly the part with errors.

The sample I provided is real code that should work pasted into your pipe’s script, it moves the node to the left by 120 pixels per second.

Thanks for help, but i use your own way