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.

asked Jan 9 in Engine by Cobra! (141 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()
answered Jan 11 by SingingApple (368 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 How to use this Q&A? before posting your first questions.