Canvas drawing with offset

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gmatheus10

I have a script to draw a little cross on the mouse position when I click with the mouse. This position is sent to another script through event handler for more functionality. I override the draw in the first script to draw the mouse position, and did the same to the receiver script. The problem is, the cross is drawn with offset on the receiver script, but the mouse position is the same when I checked with the GD.Print. I’m using GetGlobalMousePosition() , but the problem isn’t solved with GetLocalMousePosition().

https://imgshare.io/image/mousepositionbug.p0K7D8
[White is mouse - Red is PlayerController]
https://imgshare.io/image/mousepositionbug2.p0K3xK

Edit 1: After some testing, I discovered that the CanvasItem Transform is the guilty here. Still don’t know how to fix, but I can see the problem now.

:bust_in_silhouette: Reply From: gmatheus10

Using the function GetGlobalTransform().XFormInv(Vector2 position) worked, however, it changed the position of the mouse, but it drew the cross exact on the click, so I don’t know anymore what is going on.