0 votes

I get removechild: Cannot remover child node of this node
but I previously added it with add
child using a variable instance, because it tells me that this node does not exist, can someone help me?

in Engine by (53 points)

Instead of asking different variations of the same question over and over, why not just use the Comment feature provided within a question to continue the conversation in a single place? It's very confusing for people trying to help you or people seeking the same information in the future when the info is scattered between multiple questions.

Back to your question...

To get help, you're going to need to:

  • Post the offending code (using the Code Sample { } button)
  • Indicate what line is causing the error
  • Post (either as text or a screenshot) the organization of your scene tree
  • Post the exact error message you see in Godot

ok sorry look

onready var iteam_ma = load("res://Scrips materiales/Madera.tscn") 

func _process(delta):
var madera1 = iteam_ma.instance()

if madera == true && ocupado1_ma == false && ocupado_universal1 == false && ocupado2_ma == false:
    ocupado1_ma= true
    ocupado_universal1 = true

["that's how I add the node"]

if Input.is_action_pressed("Shif"):

["and that's how I want to eliminate"]

and the error is

E 0:00:16.417 removechild: Cannot remove child node Madera as it is not a child of this node.
` Condition "idx == -1" is true.
scene/main/node.cpp:1256 @ remove
Inventario.gd:58 @ _process()

1 Answer

0 votes
Best answer

So, it looks like you're creating a new, independent instance of iteam_ma in every frame with this code:

var madera1 = iteam_ma.instance()

I doubt that's what you intend to do here...

Next, you might add the current instance to the scene tree via a call to add_child() - assuming the complex if logic is all true in the current frame.

Finally, you might try to remove the current instance from the scene tree, if the Shif action is pressed in the current frame...

I'd say what's likely happening is this:

In some frame...

  • You create a new instance
  • You add that instance to the tree
  • The Shif action is not pressed, so you don't remove the instance from the tree

Now, in some future frame...

  • You create a new instance
  • You don't add it to the tree (because your if checks aren't true)
  • You attempt to remove that instance from the tree (because Shif if pressed)

Since that instance was never added to the tree, it cannot be removed from the tree, and will lead to the error you reported...

by (13,810 points)
selected by

Thanks bror
you were right what it was

 var madera1 = iteam_ma.instance()

now the instance () is created only when the logic is true and at the same time in the logic is add_chill

also for it to work well he had to put

if Input.is_action_just_pressed("Shif"):

previously the logic was

   if Input.is_action_pressed("Shif"):

this was changed because when saying is_action_pressed An error was created since an attempt was made to remove a node that had already been removed since this function is executed over and over again while the indicated key is pressed

Now with


it is executed only once when pressing the key
but of course if you press for the second time it gives you the error that there is no chill node in ...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.