ScreenToWorldPoint out of sight only in Unity editor

Hello,

I’m working on a 2D project and I want to draw a curve with a LineRenderer.
I have pixels coordinates (for a 1920*1080 screen) of that curve and with a script I transform those pixels in world points and populate the LineRenderer with world points.

But when the simulation start 80% of the curve is not visible by the camera.

My camera is Orthographic and the size is 5.4. If I import a 1920*1080 image in the scene the camera has the perfect size to display the picture.

If I build and run the project the curve is perfectly display on a 1920*1080 screen.

I don’t understand why it’s only weird in the editor.

Edit : When I chose “Maximize on play” in the game window the curve is not drawn the same way. It’s almost the same as the build & run version but not exactly.

Might be 2 things.

Window resolutions especially in Windows ( 8, 10) are tricky. Due to the window scaling the windows occasionally seem to think they have a lower resolution. We have that problem often when working on our 4k TV.

Try fiddling with scaling in the Windows settings.

In the editor you also have to keep in mind that you don’t use the whole screen.

ScreenToWorldPoint takes pixel coordinates and returns world coordinates. So far so good. However your screen is bigger than your “game” window. There’s always some kind of frame from the window and the editor. Those might also cause issues.

Try checking out these two functions:
ViewportToScreenPoint Transforms position from viewport space into screen space.
ViewportToWorldPoint Transforms position from viewport space into world space.

Notice there’s screen coordinates and viewport coordinates and its quite easy to mess these out.

If you use Input.mouseposition you get Screen coordinates. You can transform these to world space directly.