TransformControls is always retrieved when using Raycast

What I would like to do:

I would like to avoid TransformControls to be detached when clicking a group of object empty space.

What I Did:
if user clicks on an object inside a group it retrieves the intersected object then parse through parents till it finds the group. Then attach the group to the controls.If I click on an empty space then it detaches the controls.

What happens:

If I use Raycast and add the TransformControls inside the intersectObjects array the control is retrieved as intersected no matter if I click on an object or empty space.

Expected Behaviour:

I would like to retrieve the TransformControls when clicking on it and retrieve an empty array when clicking on an empty space in the canvas.

Many thanks in advance for your time.

Assuming I understood what you mean correctly - a simple solution may be to just put a hidden bounding sphere around the transform controls when they are active.

That way clicking anywhere near the transform controls will still detect collision in the raycast and prevent the controls from being detached - while clicking further away will no longer detect collision with the sphere and should detach controls nicely.

Thank you for your reply and sorry for the long delay.
I understand your solution and tried it.
In fact it didn’t worked for one reason, which is that my main problem is that the control itself apparently takes all the size of the canvas ( so when I click on an empty part I retrieve some Line object ).
Adding a bounding sphere to a control that takes all the space gets me to the point where when I think I click on an empty part I click on the bounding sphere as a result the control never gets detached when it should.

So as a synthesis I would like to thank you again and ask you if you have any other ideas how to solve my issue?

I think an axis gets attached to the mouse position on click which makes it always intersect and increase the sphere radius.


I finally manage to achieve what I want by removing the TransformControlsPlane object from the list of objects to be checked and added a couple of conditions to make this work. Thanks anyway.