Hit box not updating fast enough to rebake layer

Godot Version

4.4

Question

Godot is not removing objects from the queue fast enough to rebake layer in the same function but if i call bake later it works. Is there a way to call it on something like @onready with in the function?
Here is the function:

func _on_interact_left():
	if sprite_2d.frame == 0:
		sprite_2d.frame = 1
		hitbox0.queue_free()
		hitbox1.set_collision_layer_value(4,true)
		hitbox1.set_collision_mask_value(4,true)
		hitbox1.set_collision_layer_value(6,true)
		hitbox1.set_collision_mask_value(6,true)
		
		$"..".bake_navigation_polygon() 

You could try to Callable.call_deferred() the bake_navigation_polygon() function like: $"..".bake_navigation_polygon.call_deferred() or await for a frame before calling that function like:

await get_tree().process_frame
$"..".bake_navigation_polygon()
1 Like

The bake function will parse all the nodes with whatever properties they have the moment you call it. There is no delay there, it runs synchronous.

A queue_free() will not remove the node immediately but only on the next process idle. So if you want a node removed immediately from the SceneTree you need to use in addition e.g. remove_child() or something on that node.

A delay only exists for the actual bake when you do it on a thread (default) and for the part where the NavigationServer needs to process all the updates until the change can actually show up for new path queries.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.