The Gamepad Mouse Cursor sample doesn’t seem to be compatible with the Canvas Scaler “Scale With Screen Size” setting. If the Canvas Scaler scales the canvas, the virtual mouse cursor creates pointer events at a location different to where it’s rendered.
Did anyone experience this aswell? Any solutions?
Thanks!
Well… Nothing works… The fix also seems to does not work… And If I update to the preview versions the GamePad Mouse Cursor Sample then does not work at all.
I think have found a solution! If you copy all of the VirtualMouseInput.cs code into your own script, then make the following changes (I am using Input System v1.5.0)
Add a reference to the Canvas RectTransform component “canvasRectTransform” in the code below.
Add this function
// Clamp the virtual mouse position to the canvas
private Vector2 ClampToCanvas(Vector2 position)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, position,
m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : m_Canvas.worldCamera, out position);
return position;
}
This should work for overlay canvas’s and camera space canvas’s, and I am currently testing whether it works with world space ones. Let me know if it works for you!