Instanced TileMaps all share the same child?

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

In the game I’m developing, I’m instancing a tilemap repeatedly, to make an endless runner. Each tilemap has their own Area2D node, which when spawned in, should instance a random obstacle. The issue here, is that the obstacles instance at the first Area2D that was spawned, when the game was started. is there any way to get them to spawn at their own Area2D? I’m still pretty new to this, and I’m not seeing the issue.

Could you please share the code that’s instancing objects?

Hugo4IT | 2022-01-09 17:30

Instancing TileMap:

func _process(delta):
if spawnpos.distance_to(player.global_position) < 300:
func spawn_ground():
var spawnblock = prebuild1.instance()
spawnblock.global_position.x = spawnpos.x
spawnpos.x = spawnpos.x + groundwidth

Instancing Obstacles:

func spawn():
var conespawn = cone.instance()
conespawn.position.x = $Area2D.global_position.x + lerp(-50, 50, randf())
conespawn.position.y = $Area2D.global_position.y

OiKeTTLe | 2022-01-09 22:17