Problems with add_child_below_node

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

So I’m trying to make an Endless Runner
In this video, I’m showing my problem.
So the ,Tiles’’ or Objects move to a certain point. It isnt a collision or like that, because the objects dont have a collision yet.
There is an error in the second window of godot(the cmd) wich says WARNING: add_child_below_node: Cannot move under node Spawner as @ObjectsA@6 does not share a parent.
At: scene/main/node.cpp:1195
My code for the movement is

extends Node2D
export var speed = 5

func _ready():
	pass # Replace with function body.

func move():
	self.position.y = speed

and the script for the spawning is under a Node2D:

extends Node2D

export (Array, PackedScene) var scenes

var random_scene =
var selected_scene_index = 0
var timer

func _on_Timer_timeout():
	selected_scene_index = random_scene.randi_range(0, scenes.size()-1)
	var tmp = scenes[selected_scene_index].instance()
	add_child_below_node(self, tmp)

func _ready():
	timer = get_node("Timer")

So whats the problem?
If other info is needed for answering, just write it

:bust_in_silhouette: Reply From: Ley

I am trying to create an Endless Runner at the moment as well and Ive ran into the same exact problem you are describing. Your post has been 2 years ago so could you find a solution? I would appreciate some help. This project is something Im doing for a college task and Im honestly getting very frustrated because I just cant get it to work.
Ive got two problems actually.

  1. cant add child below node (spawner).
  2. I have a label to count the score but it continues even after the Player died and I have no clue how to make the counter react/stop when the Player dies.
    Welp :frowning:
:bust_in_silhouette: Reply From: Akuma

just had similar problem was struggling with it for the past hour,
just incase anyone gets the same problem

just use get_node("nameOfTheNode") however u like
then then use that to add the child, like


in your case, not a clue why it works like that but it did fix it for me

also, yellow error thing is an engine problem

Thank you for answering,
even tho I don’t even know anymore for what

Criepstar | 2022-12-10 16:27