idk how to solve a problem when the player gets out of the camera then queue free in 3d im trying not to use nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sucky

idk how to solve a problem when the player gets out of the camera then queue free in 3d im trying not to use nodes

:bust_in_silhouette: Reply From: Wakatta
func onScreen(spatial_node) -> bool: #if within camera view
    var rect = get_viewport().get_visible_rect()
    var camera = get_viewport().get_camera()
	var pos = camera.unproject_position(spatial_node.global_transform.origin)
	return rect.has_point(pos)

Not sure how expensive this func is so might want to not call too often