How to delete node in editor plugin?

Godot Version



I’m having an issue with an editor plugin that is printing the error message
Can't take value from empty array.

This is happening after I try and delete a node in the scene. The block seems to be deleted, but the error message keeps getting printed.

I’m using the following code to delete the node. Am I forgetting to do something? What is the right way to delete a node with an editor plugin?

var del_block:Node3D = plugin.get_node(block_path)

I would imagine you’d have to remove_child before you queue_free. Also, check where the error is happening, because you may be accessing that node after it’s gone.

I added the remove_child call, but the error is still being printed, along with two new ones. I’m also pretty sure that the node is not being used afterwards.

		var del_block:CyclopsBlock = builder.get_node(block_path)
  Can't take value from empty array.
  scene/main/node.cpp:1409 - Parameter "p_child" is null.
  scene/main/node.cpp:1437 - Condition "p_child->data.parent != this" is true.

Sorry to be useless. I think I’ll need to see your project (or a smaller demo) that show the problem.

The project is pretty big - not sure how easy it would be to create a demo.

The file causing the issue is res://addons/cyclops_level_builder/commands/, line 58.

This command is invoked by selecting a Cyclops block and then selecting Delete Selected Blocks from the Menu dropdown in the viewport’s toolbar.

It looks like a neat plugin, and you obviously are no newb!

Thought as I stare at the code in github: Why is that error happening on line 58? There’s no array (per se) there.

The two cpp errors are (I hope) related to code which runs later… because they are Node::add_child and Node::add_sibling

I may have to dl and fiddle.

I have a notion.

Deleting the block seems to work fine. I do not think the errors are related to that gdscript.
I think the error is something to do with the block one selects (to delete) being somehow remembered.

  1. Click block 105 (cyclops_blocks node)

  2. Delete it

  3. Click on any other block and you will see the Can't take value from empty array. error.

  4. Click on block 19 (easy cos it’s at end)

  5. Click around a bit and watch for that error. At some point it stops printing.

Conclusion : There is some situation with the last deleted block (and an array of blocks) that is happening when the node tree gets touched: i.e. when nodes are selected, added, removed.

I would look into your input handling code for get_parent/get_sibling calls which assume the old block is still there.

If you don’t get closer to the bug now, let me know. I have to get to my own code now!

Good luck.

Thanks. These kind of errors have been really hard to track down. I’ve been able to ignore them so far because they don’t seem to be causing any problems, but you never know.

1 Like