Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by nickmarty · Jan 29, 2017 at 01:07 PM · camerascreentoworldpointinconsistent

What makes Camera.ScreenToWorldPoint return different results with same input?

Here is the problem, the code using camera.ScreenToWorldPoint() below returns different results. I have an empty scene with one game object and two scripts attached to it, default camera script and this TestInput class:

 public class TestInput : MonoBehaviour {
 
     public new Camera camera;
 
     private void Update () {
         var testPosition = new Vector3( 90, 300, 0 );
         var worldPosition = camera.ScreenToWorldPoint ( testPosition );
         Debug.Log( Time.time +
             " screen: " + testPosition +
             " world: " + worldPosition +
             " camera.position: " + camera.transform.localPosition +
             "" );
     }
 }

Results:

 // 2.67702 screen: (90.0, 300.0, 0.0) world: (-5.3, 2.4, -10.0) camera.position: (0.0, 0.0, -10.0)
 // 2.71742 screen: (90.0, 300.0, 0.0) world: (-6.4, -1.3, -10.0) camera.position: (0.0, 0.0, -10.0)

The first result is the correct value, the second one is appearing every 4-12 updates. Here is the scene:

alt text

What do you think could cause that problem?

Update: Here is how to reproduce this issue in a new project:

  1. Create a new project;

  2. Switch target to iOS;

  3. Create new scene and add the script above;

  4. In Game view select iPhone Tall (2:3) or anything else without clearly set coordinates( not iPhone Tall 320:480);

  5. Observe the defect.

54e86e788ddd919cf2c5e7df866ad979.png (75.0 kB)
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Jan 29, 2017 at 08:56 PM 0
Share

Created test condition on my PC, but did not observe issue: Constant result over thousands of iterations.

  screen: (90.0, 300.0, 0.0) world: (-2.2, -0.1, -10.0) camera.position: (0.0, 1.0, -10.0)
 UnityEngine.Debug:Log(Object)
 TestInput:Update() (at Assets/TestInput.cs:14)


However, I did NOT see "iPhone Tall( 2:3) as an aspect ratio- so I created a new one 2x3 using "aspect ratio" and not "fixed resolution".

edit: I notice that if I CHANGE the aspect ration, WHILE "playing", I get a single result /frame with a different value. Closest I can get to replicating the issue. edit: Ah, didn't click "change platform": now I see the iphoneTall(2:3) option; but still get constant results. Hmm, I can also see the issue If I resize the unity editor window itself. (which allows for some system specific possible OS interference as a culprit...)

avatar image nickmarty Glurth · Jan 29, 2017 at 09:33 PM 0
Share

Right, when I switch the target to PC/$$anonymous$$ac/Standalone it does not happen, but when target is iOS, it does occur.

avatar image Glurth nickmarty · Jan 29, 2017 at 10:00 PM 0
Share

If I just let it sit: not for me

Show more comments
avatar image sampenguin · Apr 08, 2019 at 08:28 PM 0
Share

I think I just hit this problem in 2018.3.11. I'm trying to do a simple drag and drop operation. It works perfectly in editor, but when I deploy to a device (in my case Android, Samsung Galaxy S8) the behavior of the drag is as if the values are doubled or tripled, making the dragged object go much further than the finger movement on the screen.

I've been looking for possible causes for a few days, and the only thing I can think is it has something to do with the ppi (dpi) of the device (500 something) vs. the dev computer (72)... but I've used this method in other games without this issue, so I'm pretty stumped.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need explanation for this code 1 Answer

Need help putting an object at a point based on screen coordinates 1 Answer

mouse position on terrain 1 Answer

Indicate with markers the direction of Gameobjects which are outside of the camerafield. 0 Answers

Orthographic camera with rotation and ScreenToWorldPoint 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges