Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 yanerobot · Jun 07, 2021 at 06:42 PM · inputtouch controls

New Input System returns zero Touch position on first call

Hello. This is slice of my code:

 using UnityEngine;
 
 public class Swipe : MonoBehaviour
 {
     InputMaster input;
 
     Vector2 startPos;
 
     void Awake()
     {
         input = new InputMaster();
         input.Enable();
     }
 
     void Start()
     {
         input.Touch.Tap.performed += ctx => CachePosition();
     }
 
     void CachePosition()
     {
         startPos = input.Touch.Position.ReadValue<Vector2>();
         print(startPos)  // !prints  "(0,0)" on first call and then prints appropriate values.
     }
 }
 

What I'm trying to accomplish here is to cache screen position of tap on tap (event). And it works fine from the second call onwards. But on the first call it returns Vector.zero (0,0). I don't get what the problem might be caused by, I'll try to leave any releavant information here. These 2 input actions has no interactions or processors. "Tap" action is button bind to "Primary Touch/Tap [Touchscreen]". "Position" action is of type "value" - "Vector2" and pretty self explainatory bind to "Position [Touchscreen]".

Maybe my input settings are wrong.

Comment
Add comment · Show 2
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 monsterrungame · Jul 15, 2021 at 06:14 PM 0
Share

Really? There's no any answer for such an important issue???? Where's the support?

avatar image Hellium monsterrungame · Jul 15, 2021 at 11:07 PM 1
Share

The support is freely provided by the community.

If you want support from Unity Technologies feel free to subscribe to their premium support.

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by YienHoe · Nov 02, 2021 at 09:18 AM

@yanerobot My solution for this is to make the programme wait until the end of the first frame before calling the function again. Link to the code answer below:

https://stackoverflow.com/a/69807869/15167614

Hope this helps

Comment
Add comment · Share
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
0

Answer by msanatan · Aug 19, 2021 at 01:32 AM

I'm having the same problems... no solution as yet. I'm using v2020.3.10f1 LTS, hoping that an upgrade to 2021 would stop this issue

Comment
Add comment · Show 1 · Share
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 msanatan · Aug 19, 2021 at 02:09 AM 0
Share

@yanerobot don't upgrade to 2021, all the screen coordinates are now (Infinity, Infinity). I can't believe it got worse lol

avatar image
0

Answer by Ercova · Aug 19, 2021 at 07:04 AM

Ok, Let me tell the possibilies then. First => make sure your Tap action is Button and interactions is selected press and release. and for Bindings for Tap action will be PrimaryTouch/TouchContact? and Left Mouse Button.

Second make sure your Position action is Pass through and Type is Vector2. and For bindings will be again Primary Touch/Position and Mouse Position.

 input.Touch.Tap.canceled+= _ => CachePosition();
Comment
Add comment · Show 3 · Share
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 msanatan · Aug 19, 2021 at 10:39 AM 0
Share

I did your set up, with the exception of mouse pointers:

Here's the input action for pressing: https://ibb.co/98fr3qn

And the input action for position: https://ibb.co/bLL8vTg

And these are my logs of screen and world coordinates: https://ibb.co/JxKnWYR

When I read the value, I always get (0, 0), like the OP.

avatar image msanatan msanatan · Aug 19, 2021 at 01:32 PM 1
Share

I realized the bug happens when the binding is Primary Touch/Touch Contact. It picks up the right position when I set it to Touch 0/Touch Contact, or event Primary Touch/Tap. It's just Primary Touch/Touch Contact that's not working. Give it a try @yanerobot

avatar image joext msanatan · Mar 30 at 09:28 AM 0
Share

@msanatan you are right! Thanks.

avatar image
0

Answer by imaxs · Aug 26, 2021 at 04:35 PM

I think this should help you:


Pressing and position actions


Subscribing to events Note: Subscribing to the "PrimaryTouch.started" event is done after "PrimaryTouchPosition.started" event is called once.

 m_InputControllers.Touch.PrimaryTouchPosition.started += (context) => {
       StartPrimaryTouch(context);
       m_InputControllers.Touch.PrimaryTouch.started += context => StartPrimaryTouch(context);
 };
 m_InputControllers.Touch.PrimaryTouch.canceled += context => EndPrimaryTouch(context);

read positions

 private void EndPrimaryTouch(InputAction.CallbackContext context) => Debug.Log(m_InputControllers.Touch.PrimaryTouchPosition.ReadValue<Vector2>());
 
 private void StartPrimaryTouch(InputAction.CallbackContext context) => Debug.Log(m_InputControllers.Touch.PrimaryTouchPosition.ReadValue<Vector2>());



UPD: I forked their repo on github (v 1.1.0), made some fixes and improvements. So now this seems to be fixed, at least for me. Check this out at: GitHub


now it works right (without subscription inside the "PrimaryTouchPosition.started" event)

 private void Start()
 {
     m_InputControllers.Touch.PrimaryTouch.started += context => StartPrimaryTouch(context);
     m_InputControllers.Touch.PrimaryTouch.canceled += context => EndPrimaryTouch(context);
 }
 
 
 private void EndPrimaryTouch(InputAction.CallbackContext context) => Debug.Log(m_InputControllers.Touch.PrimaryTouchPosition.ReadValue<Vector2>());
     
 private void StartPrimaryTouch(InputAction.CallbackContext context) => Debug.Log(m_InputControllers.Touch.PrimaryTouchPosition.ReadValue<Vector2>());


Note: There are no changes in the Input Actions (looks the same as on the screenshot above), but you should add a new component.


Player Input  Component

Comment
Add comment · Share
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
0

Answer by davidhernandez · Mar 04 at 05:23 AM

Still an issue on 2020.3.23 with Input System 1.3.0

It also happens when I disable the Touch input, the first touch event will return a vector2 with zero values

Comment
Add comment · Share
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

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

159 People are following this question.

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

Related Questions

How to distinguish between two touch screens for input in android 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

How do you get position from fingerId 1 Answer

When pressing a button, it counts as pressing the screen and the button [New Input System] 0 Answers

How can we make touch controls like Hole.io/ Bumper.io? 0 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