0 votes

I'm trying to make come objects get destroyed by code, so certain levels will only have the objects it needs, and doesn't need to compute objects it doesn't.

However, after triple checking I got the nodepaths correct, the objects just aren't getting destroyed.

Here's the (relevant) code:

export(Array) var itemsToDelete

func _ready():
    if itemsToDelete.size() > 0:
        for item in itemsToDelete:
            print(item)
            get_node(item).free()

What do I do? I'm using Godot 2.1, by the way.

in Engine by (171 points)

use queue_free() instead

using free can cause errors unless you REALLY know what you are doing and queue_free() makes the object disappear in the end of its usage(aka end of scene)

1 Answer

0 votes

Use queue_free() instead of free()

Something like this:

export(Array) var itemsToDelete

func _ready():
    if itemsToDelete.size() > 0:
        for item in itemsToDelete:
            print(item)
            get_node(item).queue_free()
by (418 points)
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.