I cannot say for sure, but I have a few suggestions/thoughts:
| If I remember correctly, ..
gets whatever is above it. So get_node(“../b”)
is equivalent to get_parent().get_node(“b”)
. Is b
the name of the Area2D? If it is, then I’d just use self.add_child(b)
.
| If what I wrote above is true, then the reason none of the snippets you are providing are working is because the node isn’t actually attached to the node this script is attached to, but rather the parent node that the script is attached to. Using self.add_child(b)
will parent b
to the node this script is attached to (you can remove self
if you want, and just use add_child(b)
instead)
| Another thing, the name of the newly instanced node will have some generated name, something like <insert node name here>@1
or something like that. If you want to use something like get_node(“b”)
, then you need to rename the node to b
. You can do this in _on_Button_pressed
by adding b.name = “b”
| Finally, and you may already know this, but you cannot use b.queue_free
unless b
is stored outside of your _on_Button_pressed
function. If it is already stored outside of the _on_Button_pressed
function, then you need to remove var
from var b = Robot.instance()
. If you want to access it again, then I’d highly suggest storing b
in a variable outside of your functions, so you can access it at any time, from any function.
I’m not sure if anything I wrote will work. Currently I’m away from my development machine, so I cannot test any code.
If you link your project (or an example project showing the same issue), then I’ll take a look later and see if I can solve the problem (if you want).