![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | thoth |
I have identified a node using a raycast. I would like to remove that node from the scene tree. If I use
func _physics_process(_delta):
#...
remove_child(nodec)
nodec.queue_free()
The StaticBody that is nodec seems to be gone (raycasts no longer hit it), but the MeshInstance that was its child is still visible?
(Edit) The result of get_children().size()
appears to be holding steady at 262 no matter how many I delete. Are the results from the get_world().direct_space_state.intersect_ray(...)
in a different tree than my scene nodes?
(Edit) In case it helps, here is the code that constructs the nodes I am trying to delete
func make_bar(x,z, y_size, radius):
var bar1 = MeshInstance.new()
var mesh = CubeMesh.new()
mesh.surface_set_material(0, material)
bar1.mesh = mesh
bar1.translation = Vector3(x, y_size,z)
bar1.scale = Vector3(radius, y_size, radius)
var n
if true:
var body = StaticBody.new()
body.add_child(bar1)
body.add_child(CollisionShape.new())
bar1.create_convex_collision()
n=body
else:
n=bar1
bars.push_back(n)
add_child(n)
return n
What is the correct procedure to remove the node and all its descendants from existence?
Just calling queue_free()
should remove both the targeted node and all of its children from the scene tree. Are you sure that’s not the case?
See the 3.2 docs here (though, that’s a really old version of Godot).
Node — Godot Engine (3.2) documentation in English
jgodfrey | 2023-01-24 14:52
Just a thought - how and when are you checking for the existence of the node(s) you’ve deleted? If you’re checking immediately after calling queue_free()
, the deletion may not have happened yet (it is queued
after all). So, it could take a number of frames depending on the situation…
jgodfrey | 2023-01-24 15:22
I am checking using my eyeballs. The mesh “cubes” are not disappearing. I will update the question with the code that constructs the nodes.
thoth | 2023-01-24 15:33
Are you sure nodec is the staticbody?
SteveSmith | 2023-01-24 15:41
Also, is this a custom build of Godot?
SteveSmith | 2023-01-24 15:42
When I stuff nodec.get_type()
into the text of a label as part of a debug message, it reports StaticBody
.
This build of Godot is installed from the Ubuntu 20 LTS app “store” . Its About dialog identifies it as v3.2.stable.custom_build .
thoth | 2023-01-24 15:52