xyz Nope, even calls using the state object sourced from outside of physics_process() results in "space->locked" errors.
test code:
var thread = Thread.new()
func _ready():
var dss = await AW_get_dss()
var c = Callable(self,"thread_func")
thread.start(thread_func.bind(dss))
print("done!")
func thread_func(dss):
randomize()
for x in range(90000):
var p1 = Vector3(randf_range(0,20),randf_range(0,20),randf_range(0,20))
var p2 = Vector3(randf_range(0,20),randf_range(0,20),randf_range(0,20))
var r = simplified_line_of_sight_test([p1,p2,dss])
print(str(x)+": "+str(r))
func _physics_process(delta):
var p1 = Vector3(randf_range(0,20),randf_range(0,20),randf_range(0,20))
var p2 = Vector3(randf_range(0,20),randf_range(0,20),randf_range(0,20))
var dss = get_world_3d().direct_space_state
var r = simplified_line_of_sight_test([p1,p2,dss])
print(str("phy")+": "+str(r))
func AW_get_dss():
await get_tree().physics_frame
return get_world_3d().direct_space_state
func simplified_line_of_sight_test(params_arr):
var perception_pos = params_arr[0]
var perceived_entity_pos = params_arr[1]
var dss = params_arr[2]
var exclude_arr = []
#do raycasts
var is_obstructed = true
var x = PhysicsRayQueryParameters3D.new()
x.from = perception_pos
x.to = perceived_entity_pos
x.exclude = exclude_arr
var _result = dss.intersect_ray( x )
if _result.size() == 0:
is_obstructed = false
return !is_obstructed
There seems to be no way of offloading physics from the physics thread. This is now an issue for me because it means that every time I want to do a raycast from any other thread, I need to await a physics process frame.
I could try and force the physics thread into an alternative process loop that only updates upon request (like I did for threads here), allowing me to make physics calls without delay, but doing that would disable all physics_process() loops across my entire project, and if any nodes rely on physics_process() they would likely cease to work.
Overall really sucks; what if you want to make a bunch of disjointed physics calls without forcing the physics process to stall or being forced to wait upon process frames several times? Ideally there would be a way to duplicate the direct_space_state object to make physics tests independently from the physics server.