Custom cursor not following native cursor when hovering over button component

Has anyone ran into this issue before? I have a button component that the user presses and highlights a different color in the hover state, but when I move over the button the custom cursor stops getting the position of the native cursor.

Here’s my code:

onLoad() {
        input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this)
}

onMouseMove(event: EventMouse) {
        const mousePos = event.getUILocation();
        this.customCursor.setWorldPosition(mousePos.x, mousePos.y, 0);
}

The result:

Tested this come more and it looks like this is happening on any UI Component used. I assume these components are blocking the event handlers.

any way to have these two handlers work together and not have the UI component handler override my handler?

Found the solution. I put the event handler on the canvas node instead of using Input. Here’s how I used it in my GameCtrl script.

@ccclass('GameCtrl')
export class GameCtrl extends Component {

    @property(Node)
    customCursor: Node

    onLoad() {
        let canvas = find("Canvas") // find the canvas node
        let gameCanvas = document.getElementById("GameCanvas") // this ID is generated by CC you can inspect the element on the browser
        gameCanvas.style.cursor = "none" // hides browser cursor
        canvas.on(Node.EventType.MOUSE_MOVE, this.onMouseMove, this)
    }

    onMouseMove(event: EventMouse) {
        const mousePos = event.getUILocation()
        this.customCursor.setWorldPosition(mousePos.x, mousePos.y, 0)
    }
}

You can also hide/show the cursor just by using this.customCursor.active and setting to true or false whenever you need to like when you pause the game, game over, etc.

I’m sure this approach wont work in a Windows native game but I’ll keep testing.