Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Bug ScreenToWorldPoint gives wrong result if Scene view is open

Discussion in 'Editor & General Support' started by castor76, Apr 7, 2021.

  1. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,511
    ScreenToWorldPoint seems to give wrong result if Scene view is open.

    The exactly the same code like :

    mainCam.ScreenToWorldPoint(screenPos);

    gives completely different values if my Editor Scene view is showing or not.

    Unity 2021.1f1 2DRenderer Orthographic camera
     
  2. Shinci

    Shinci

    Joined:
    Jul 21, 2019
    Posts:
    1
    I was checking this problem here. I noticed that when we made a log of the current camera, the results were different.
    upload_2021-9-24_0-10-2.png

    upload_2021-9-24_0-8-32.png

    The solution that I found was to check if my camera is the current camera else the script ignores the call.
    upload_2021-9-24_0-14-36.png

    But I still don't understand why this works because we specify the camera to call the ScreenToWorldPoint. It looks like Unity uses the current camera values to it.
    upload_2021-9-24_0-23-54.png
     
  3. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,511
    Sounds like my problem. Yeah, I also specify the exact camera to use to call ScreenToWorldPoint. But instead, it seems like it may be using the scene camera no matter what if I have the scene window open and visible.

    Very strange and very annoying!

    I tried to create small repro case, but I failed reproducing it in my trimmed project.

    But still, this should never happen?