Kill an instance of a scene

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

I’m creating multiple instances (j.instance()) of a scene as entities, and I want to be able to kill one of them. I’ve tried using “queue_free()” but that destroys the whole scene and I’m not able to destroy them any more. What’s the best way to do this?

I think you can append those instances into an array and check the array members.
If they met the condition to be killed, then you can call queue_free() on them.

asetyowatir | 2018-05-07 12:31

This only works for one instance, after which I get a “Node not found” error.

hotmailking | 2018-05-07 12:36

:bust_in_silhouette: Reply From: anakimluke

If you want to simply remove a node/scene, you can use my_node.queue_free().

If queue_free() is used with no name and dot to the left of it(like queue_free() instead of something.queue_free()), then self is implied and it means the same as self.queue_free(); it queues for removal the node you are calling this function from.

self refers to current class instance[1], it is always available and is provided as an option for accessing class members, but is not always required[2].

I’ve tried something like this. Accessed the instance I was trying to remove and called “instanceName.queue_free()”, but the same issue. It removes an instance the first time, but any time I try to do it with another instance of the same scene it doesn’t work and returns a “Node not found” error, as if it is removing the scene all together.

hotmailking | 2018-05-12 07:38

Are you sure you’re not referring to the same node on the second time queue_free() is called?

anakimluke | 2018-05-13 17:49