@SimonDufour @antoine-unity we have tested your example and it works perfectly with mouse but in XR with controllers it does not work well because the Vector2 that arrives in the following function appears with very strange negative values:
https://docs.unity3d.com/ScriptReference/UIElements.PanelSettings.SetScreenToPanelSpaceFunction.html
I understand that it is a bug, isn’t it? It seems that in this part of the code that checks the eventSource it only takes into account touch, pen and mouse…And I guess that’s part of the problem.
I can only see this code in 2023.x branches (I am on 2022 LTS) so I don’t know if it is the same or not.
Is there any way to unblock this problem? We have tried not to use that Vector2 and to try to know in every moment which XR controller InputSystem is processing to change the controller pivot transform that processes.
The rest of the missing code is from your own example:
private XRController currentController = null;
InputSystem.onEvent += (eventPtr, device) =>
{
if (device is XRController controller)
{
currentController = controller;
}
else
{
currentController = null;
}
};
panel.SetScreenToPanelSpaceFunction(ScreenCoordinatesToRenderTexture);
private Vector2 ScreenCoordinatesToRenderTexture(Vector2 screenPosition)
{
if (currentController == null) return new Vector2(float.NaN, float.NaN);
Transform pointerPivot;
if (XRController.leftHand == currentController)
{
pointerPivot = myLeftControllerPivot;
}
else
{
pointerPivot = myRightControllerPivot;
}
Ray ray = new(pointerPivot.position, pointerPivot.forward);
if (Physics.Raycast(ray, out RaycastHit hitInfo))
{
return GetPositionFromHit(hitInfo);
}
return new Vector2(float.NaN, float.NaN);
}
What happens to us is that if you have one controller active it works but if you have both at the same time it is as if they were competing in the same frame and only one of them is processed (in our case the right one).
Is there any solution to this problem? Thank you.