Open theyouknow opened 7 months ago
A node does only update once each loop at the begin, usually before scripts, e.g. the RayCast3D updates its collider info only once at the begin of each physics process step. The deleting of queue_free() objects happen at different times in the main loop. In this case the colliding boolean of the node is set to true because by the time the node did the collision check it was true. That the collider object is marked for delete after and deleted, the node has no way to notice this before the next physics step update.
If you need immediate up-to-date info from the physics system use physics direct space queries. Nodes always add a processing delay and some update quirks because that is just how the SceneTree updates them. They also need to do their own internal book-keeping so are never in perfect sync with the server.
Perhaps the docs could be amended to accomodate this case, as currently they give the impression is_colliding
and get_collider
always match (same goes for other methods with similar descriptions):
As a workaround for OP, you can use the following before setting the global_position
in that code:
if (ray_cast.get_collider() != null):
or if is_instance_valid(ray_cast.get_collider()):
If you need immediate up-to-date info from the physics system use physics direct space queries. Nodes always add a processing delay and some update quirks because that is just how the SceneTree updates them. They also need to do their own internal book-keeping so are never in perfect sync with the server.
There's also RayCast2D/3D.force_raycast_update
method which can be used to force syncing RayCast2D/3D
state according to the physics direct space state.
Tested versions
I'm not sure, I only have the v4.2.1 version of godot, so I haven't tried it in other versions of godot.
System information
Godot v4.2.1.stable - Windows 10.0.22631 - Vulkan (Forward+) - integrated AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.; 31.0.12044.3) - AMD Athlon Silver 3050U with Radeon Graphics (2 Threads)
Issue description
Steps to reproduce
Here's the code:
@onready var i = $Indicator # The indicator is just a mesh 3d @onready var ray_cast = $RayCast3D # You'll also need to create a raycast3d
func _physics_process(_delta):
Minimal reproduction project (MRP)
The bug.zip Open the project in editor mode, press run project, and then left click one of the cubes, the error should occur.