ScreenToWorldPoint() not working properly using a RenderTexture

Hello there!


I’m developing a 2D pixel-perfect game wihere I use 2 cameras, for the rendering with a target texture.


Camera.main.ScreenToWorldPoint() works perfectly when I don’t use a target render texture but in all my tests the crosshair doesn’t follow the cursor properly IF I use a target render texture with a smaller size, say 512x288.


I discovered that if I use in playmode the same exact same of the display size, there it works correctly, so I’m sure it has something to do with the scaling the screen where I display the game (16:9 doesn’t work for example, only the exact width and height).


Here’s how I do the crosshair script to follow the mouse.
!(https://user-images.githubusercontent.com/10330846/35353359-b52d86cc-0125-11e8-9309-05a8d96b1925.png)

And yeah…
With render texture enabled
!(https://user-images.githubusercontent.com/10330846/35353253-5fdc879a-0125-11e8-8e0d-bfc1aefc85a8.png)
Imagine the red arrow is actually the mouse pointer.

With render texture disabled
!(https://user-images.githubusercontent.com/10330846/35353507-28991a72-0126-11e8-8dfa-ff36626e8dfc.png)

Thanks in advance to anyone who knows how to solve this issue.

Have same issue Unity 2019.2.2. If you use targetTexture for that camera ScreenToWorldPoint will return strange values.