Parallax2D and spawns

Godot Version

4.7

Question

Ok so I am trying to have a scrolling parallax ground that comes up for a bit then falls back down below the viewport (think like a ship entering a planet then exiting)

what I want to have is these turrets to randomly spawn on the ground and move with the parallax ground while its going up and down. the turrets must spawn off screen to the right then come in and shoot at your ship.

The issue I have with my code is this version does almost all I want but for some reason my turrets vanish halfway and then reappear without the gun that fires at the player but continues to spawn more turrets normally that all vanish halfway to only respawn without their turrets

The other method I had was to move my spawner out of the parallax tree and just spawn them with their own movement but they don’t move off camera when the ground moves down or up

extends Parallax2D



var margin = 585
var screen_height = ProjectSettings.get_setting("display/window/size/viewport_height")
var screen_width = ProjectSettings.get_setting("display/window/size/viewport_width")

var random_time = randf_range(6.5, 9.0)
@onready var ground_front: Parallax2D = %ground_front
@onready var ground_1: TextureRect = $ground1
@onready var timer: Timer = $"../Timer"
@onready var armor_spawner_component: ArmorSpawnerComponent = %ArmorSpawnerComponent



func _ready() -> void:
	ground_front.autoscroll.y = -11
	await get_tree().create_timer(3.0).timeout
	ground_front.autoscroll.y = 0
	await get_tree().create_timer(60.0).timeout
	ground_front.autoscroll.y = 11
	await get_tree().create_timer(4.0).timeout
	ground_front.autoscroll.y = 0
	await get_tree().create_timer(1.5).timeout
	queue_free()


func _on_timer_timeout() -> void:
	await get_tree().create_timer(random_time).timeout
	armor_spawner_component.spawn(Vector2(screen_width, randf_range(600, margin)))
	timer.start()

Why not make the turrets children of the ground node so their movement is handled automatically? Or maybe I’ve misunderstood the setup.

oh sorry, I managed to fix my issue by simply having the spawn move on its own instead of part of the parallax node.

I think the issue was my turret being part of the parallax ended up being … freed when it got close to the middle then being respawned off camera.

Ether way, I managed to fix it and worked out how to get more fun stuff to work.