I am building a VR project that uses 2 area nodes with a sphere collider as children of the VR controllers to detect what object is grabbable by the user. Here's the code:
var colliding_with = null
func area_enter_rb(body: RigidBody): #connected to signal
print("body entered, colliding_with= ", colliding_with)
if colliding_with == null:
colliding_with = body
body.get_node("mesh").material = body.material_selected #hilight material
print("entering finished, colliding_with= ", colliding_with)
else:
print("entering failed")
func area_exit_rb(body: RigidBody): #connected to signal
print("body left, colliding_with= ", colliding_with)
if colliding_with != null:
colliding_with = null
body.get_node("mesh").material = body.material_normal #default material
print("exiting finished, colliding_with= ", colliding_with)
else:
print("exiting failed")
As far as I can tell by the print statements, everything seems to be running as it should; however (especially when multiple objects go in and out the area collider) it can happen that an object gets stuck on the hilighted material, even when the area is no longer touching it. What could be the issue? Maybe some enter/exit events do not register sometimes? Or are these functions running asyncrounously, leading to some shared resources issues?
(Btw the code
formatting seems to be completely broken judging from the preview EDIT: solved by using ``` instead of `)